首页 > 文章详情 > Centos7 源码编译安装 Mysql5.7.24

Centos7 源码编译安装 Mysql5.7.24

原创 YuanDong 2019-10-08 浏览量(110)

安装步骤

下载源码包至 /usr/local/src/ (建议去官网下载)

 官网:https://dev.mysql.com/downloads/mysql/5.7.html
 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

解压源码包

 [root@xxxx src]# tar -xvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

移动源码包路径

 [root@xxxx src]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

新建data目录(数据库文件存放的文件夹)

[root@xxxx src]# mkdir /usr/local/mysql/data

新建mysql用户、mysql用户组

[root@xxxx src]# groupadd mysql                 # mysql用户组
[root@xxxx src]# useradd mysql -g mysql     # mysql用户

将/usr/local/mysql的所有者及所属组改为mysql

[root@xxxx src]# chown -R mysql.mysql /usr/local/mysql

安装依赖扩展

[root@xxxx src]#  yum  install -y numactl libaio

初始化安装mysql

[root@xxxx src]#  /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

[root@xxxx src]#2019-08-19T10:30:57.119712Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
[root@xxxx src]#2019-08-19T10:30:58.175707Z 0 [Warning] InnoDB: New log files created, LSN=45790
[root@xxxx src]#2019-08-19T10:30:58.326135Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
[root@xxxx src]#2019-08-19T10:30:58.391645Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6edf9f34-c26c-11e9-92d6-00163e301bc7.
[root@xxxx src]#2019-08-19T10:30:58.394653Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
[root@xxxx src]#2019-08-19T10:30:58.395179Z 1 [Note] A temporary password is generated for root@localhost: xT57>!j,tri!


注:在初始化时如果加上 –initial-insecure,则会创建空密码的 root@localhost 账号,否则会创建带密码的 root@localhost 账号,密码直接写在 log-error 日志文件中(在5.6版本中是放在 ~/.mysql_secret 文件里,更加隐蔽,不熟悉的话可能会无所适从)

编辑mysql 配置文件

[root@xxxx src]# vim /etc/my.cnf
###  将这个加入/etc/my.cnf  文件中
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消登录密码验证
skip-grant-tables  ##安装完成之后把这行删除
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

添加mysql 服务

### 添加服务
[root@xxxx src]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

### 设置开机自启
[root@xxxx src]# chkconfig mysql on

### 启动mysql服务
[root@xxxx src]# service mysql start
[root@xxxx src]# Starting MySQL.               [  OK  ]        #到这里,恭喜你已经成功安装

首次登录mysql 修改root 用户登录密码

[root@xxxx ~]#  /usr/local/mysql/bin/mysql -u root -p  #回车即可
[root@xxxx mysql]# use mysql;
[root@xxxx mysql]# update user set authentication_string=password('123456') where user='root';
[root@xxxx mysql]# flush privileges;
[root@xxxx mysql]# exit;

#退出后将 /etc/my.cnf中的 skip-grant-tables 删除(注:这一行代表免密登录)

### 重启Mysql服务
[root@xxxx src]# service mysql restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL.                                            [  OK  ]

### 再次登录 mysql  修改root 密码(注:本人也不知道为什么,必须执行 下面命令)
[root@xxxx src]# ALTER USER 'root'@'localhost' IDENTIFIED BY '您的新密码';
[root@xxxx src]# flush privileges;

到这了mysql 安装已经结束...

开启MySQL远程访问权限 允许远程连接

登陆mysql数据库 查看user表

mysql> use mysql;
Database changed
mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

##可以看到在user表中已创建的root用户。host字段表示登录的主机,其值可以用IP,也可用主机名,

修改表的方法

#将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%
update user set host='%' where user = 'root';  
or
#将host字段的值改为IP 表示指定的ip可访问
update user set host='IP' where user = 'root'; 

## 根据你的需求设置即可
mysql> update user set host='%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from user;
+-----------------+---------------+
| host            | user          |
+-----------------+---------------+
| %               | root          |         
| localhost       | mysql.session |
| localhost       | mysql.sys     |
+-----------------+---------------+
3 rows in set (0.00 sec)

授权法

mysql> GRANT ALL ON *.* to testuser@'127.0.0.1' IDENTIFIED BY '这是密码';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user;
+-----------------+---------------+
| host            | user          |
+-----------------+---------------+
| %               | root          |
| 127.0.0.1       | testuser      |
| localhost       | mysql.session |
| localhost       | mysql.sys     |
+-----------------+---------------+
5 rows in set (0.00 sec)

关于mysql 服务启动命令

#启动mysql服务
[root@xingjian src]# service mysql start          
Starting MySQL.                                            [  OK  ]

#重启mysql服务
[root@xingjian src]# service mysql restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL.                                            [  OK  ]

#停止mysql服务
[root@xingjian src]# service mysql stop
Shutting down MySQL..                                      [  OK  ]

热门评论 (0)

网友评论 0 条评论 / 0 人参与