MySQL-5.7.28比MySQL5.6.36源码安装多了个boost包。
先下载MySQL-5.7.28源码包和boost_1.5.0源码包:
[root@mysql src]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28.tar.gz
[root@mysql src]# wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
下载好后,将两个包解压在同一目录下,比如usr/local/mysql:
[root@mysql src]# tar -zxf mysql-5.7.28.tar.gz -C ./mysql
[root@mysql src]# tar -zxf boost_1_59_0.tar.gz -C. /mysql/boost
安装依赖包:
[root@mysql src]# yum install -y gcc gcc-c++ cmake bison ncurses-devel openssl-devel
若不安装ncurses-devel和openssl-devel,会有如下报错:
CMake Error at cmake/ssl.cmake:66 (MESSAGE):
Please install the appropriate openssl developer package.
Call Stack (most recent call first):
cmake/ssl.cmake:260 (FATAL_SSL_NOT_FOUND_ERROR)
CMakeLists.txt:573 (MYSQL_CHECK_SSL)
然后预编译,这个过程会比较长:
[root@mysql src]# cd /usr/local/src/mysql
[root@mysql mysql]# cmake \
-DMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DEFAULT_CHARSET=utf8 \
-DEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_BOOST=./boost
注意:-DWITH_BOOST=./boost 一定是boot解压后的位置,不然会报错;
预编译完成,就可以 安装了:
[root@mysql mysql]# make -j 4 && make install
初始化:
[root@mysql ~]# useradd -M -s /sbin/nologin mysql
[root@mysql ~]# cd /usr/local/mysql
[root@mysql mysql]# bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
[root@mysql mysql]# chown mysql -R .
注意:初始化完成后,会出现数据库的初始登录密码。
创建配置文件:
[root@mysql ~]# cat /etc/my.cnf
[client]
port = 3306
[mysqld]
datadir=/usr/local/mysql/data
# 禁止主机名解析
skip_name_resolve=on
# ibd文件单独存放
innodb_file_per_table = on
port = 3306
socket = /tmp/mysql.sock
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
log-bin=mysql-bin
server-id = 1
[mysqld_safe]
log-error = /usr/local/mysql/logs/error.log
pid-file = /usr/local/mysql/pids/mysqld.pid
创建log、socket与pid文件与相关存放目录,并修改权限:
[root@mysql src]# mkdir /usr/local/mysql/{logs,pids}
[root@mysql src]# touch /usr/local/mysql/logs/error.log
[root@mysql src]# touch /usr/local/mysql/pids/mysqld.pid
[root@mysql src]# chown -R mysql.mysql /usr/local/mysql/logs
[root@mysql src]# chown -R mysql.mysql /usr/local/mysql/pids
添加PATH变量,不然无法使用mysql命令打开数据库:
[root@mysql src]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@mysql src]# source /etc/profile.d/mysql.sh
拷贝mysql.server作为mysql服务启动脚本文件:
[root@mysql src]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
启动服务:
[root@mysql src]# service mysqld start
初次登陆前先修改/etc/my.cnf,加上“skip-grant-tables”用来跳过密码验证的过程,然后重启mysql服务,直接使用mysql命令即可登录数据库:
[root@mysql1 mysql]# vim /etc/my.cnf
[client]
port = 13306
[mysqld]
datadir=/usr/local/mysql/data
# 禁止主机名解析
skip_name_resolve=on
#跳过密码验证
skip-grant-tables
# ibd文件单独存放
innodb_file_per_table = on
port = 13306
socket = /tmp/mysql.sock
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
log-bin=mysql-bin
server-id = 1
[mysqld_safe]
log-error = /usr/local/mysql/logs/error.log
pid-file = /usr/local/mysql/pids/mysqld.pid
[root@mysql1 mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@mysql1 mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed;
修改密码:
mysql> update mysql.user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
再把配置文件的跳过密码验证注释掉,重启MySQL,然后使用密码登录:
[root@mysql1 mysql]# vim /etc/my.cnf
[client]
port = 13306
[mysqld]
datadir=/usr/local/mysql/data
# 禁止主机名解析
skip_name_resolve=on
#跳过用户认证
#skip-grant-tables
# ibd文件单独存放
innodb_file_per_table = on
port = 13306
socket = /tmp/mysql.sock
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
log-bin=mysql-bin
server-id = 1
[mysqld_safe]
log-error = /usr/local/mysql/logs/error.log
pid-file = /usr/local/mysql/pids/mysqld.pid
[root@mysql1 mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
登录数据库:
[root@mysql1 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
此处要求修改密码:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
按照要求修改密码,必须是强口令:
mysql> alter user 'root'@'localhost' identified by 'Aa123456!';
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
修改MYSQL数据库中的USER表,将root对应的localhost修改为%,不然无法使用Navicate登录,会报“1130-host … is not allowed to connect to this MySql server,MySQL”:
mysql> update user set host='%' where user='root' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)