由于项目需要,要将数据库升级到mysql5.7 以上版本,在升级过程中发现,mysql5.7.19版本与mysql5.6版本相差较大,整个安装过程:
1 下载安装包
mysql 5.7.19版本的安装, 安装包有多种,最方便的下载已经编译好的二进制安装包mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz, 下载后直接解压就可以使用。
tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.19
2 创建数据库的目录及账号
mkdir -p /www/mysql/data 创建存放数据库文件的目录。
groupadd mysql 创建系统的数据库组。
useradd -g mysql mysql 创建系统数据库账号。
chown -R mysql:mysql /www/mysql/data 修改数据库存放文件目录权限。
3、初始化数据库
以上基本操作完成后,就要进行数据库的初始化操作,5.7以上版本初始化操作与5.6版本有所不同, 在5.7版本上如果使用5.6版本的方法进行初始化操作会出现啥情况
./bin/mysql_install_db --user=mysql --datadir=/www/mysql/data 2016-01-21 11:29:05 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2016-01-21 11:29:10 [ERROR] The bootstrap log isn't empty: 2016-01-21 11:29:10 [ERROR] 2016-01-21T03:29:05.633658Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2016-01-21T03:29:05.641584Z 0 [ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'
可以看到mysql_install_db is deprecated,说不赞同使用mysql_install_db,推荐使用的方法是:
Please consider switching to mysqld --initialize ,Please consider using --initialize instead
正确的初始方式如下:./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.19/ --datadir=/www/mysql/data,如果datadir目录有文件,则会报以下错:
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.19/ --datadir=/www/mysql/data 2016-01-21T05:43:56.355999Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-01-21T05:43:56.357796Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2016-01-21T05:43:56.357814Z 0 [ERROR] Aborting该错误提示,说明 /www/mysql/data下这个目录下已经有文件, 处理方法删除该目录下的文件 rm -rf /www/mysql/data/*删除完成之后重新运行初始化命令。./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.19/ --datadir=/www/mysql/data2016-01-21T05:47:01.804937Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2016-01-21T05:47:03.552899Z 0 [Warning] InnoDB: New log files created, LSN=457902016-01-21T05:47:03.816849Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2016-01-21T05:47:03.883956Z 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: 660686ae-c002-11e5-843e-00163e0217d7.2016-01-21T05:47:03.886131Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2016-01-21T05:47:03.887120Z 1 [Note] A temporary password is generated for root@localhost: fQ!bAzawA3a:
mysql 5.7 以上版本与5.6版本另一个不同之处,就是初始化完成之后,会生成一个临时密码:A temporary password is generated for root@localhost: fQ!bAzawA3a:
拷贝配置文件 cp /usr/local/mysql-5.7.19/support-files/my-default.cnf /usr/local/mysql-5.7.19/my.cnf
修改配置文件中的选项:
basedir = /usr/local/mysql-5.7.19 datadir = /www/mysql/data port = 3306 server_id = 100 socket = /tmp/mysqld.sock
5 启动数据库
/usr/local/mysql-5.7.19/bin/mysqld_safe --defaults-file=/usr/local/mysql-5.7.19/my.cnf &
6 登录数据库
mysql -uroot -pfQ!bAzawA3a:
登录之后,执行任何操作都会提示你要修改密码:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码:
ALTER USER USER() IDENTIFIED BY '123456';
以上整个步骤,5.7.19数据库就安装完成。