多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> 本文是基于MySQL-5.7.7-rc版本,未来可能 还会发生更多变化。本节开始讲5.7版本中的新特性。 ## 安全性 a. 用户表 mysql.user 的 plugin字段不允许为空, 默认值是 mysql_native_password,而不是 mysql_old_password,不再支持旧密码格式; b. 增加密码过期机制,过期后需要修改密码,否则可能会被禁用,或者进入沙箱模式; c. 使用 mysql_install_db 初始化时,默认会自动生成随机密码,并且不创建除 root@localhost 外的其他账号,也不创建 test 库; ### 新特性实践 执行 mysql_install_db 进行新实例初始化: ~~~ [yejr@imysql.com]# ./bin/mysql_install_db --user=mysql --datadir=/data/mysql/ 2015-06-24 13:55:29 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2015-06-24 13:55:38 [ERROR]   Child process: /opt/17173_install/mysql-5.7.7-rc-linux-glibc2.5-x86_64/bin/mysqld terminated prematurely with errno= 32 2015-06-24 13:55:38 [ERROR]   Failed to execute /opt/17173_install/mysql-5.7.7-rc-linux-glibc2.5-x86_64/bin/mysqld --bootstrap --datadir=/data/mysql --lc-messages-dir=/usr/share/mysql --lc-messages=en_US -- server log begin -- mysqld: [Warning] --bootstrap is deprecated. Please consider using --initialize instead -- server log end -- ~~~ 可以看到提示 mysql_install_db 已经不再推荐使用了,建议改成mysqld –initialize 完成实例初始化。 改成 mysqld –initialize 后,如果 datadir 指向的目标目录下已经有数据文件,则会有类似提示: ~~~ [yejr@imysql.com]#./bin/mysqld --user=mysql --basedir=/opt/17173_install/mysql-5.7.7-rc-linux-glibc2.5-x86_64/ --datadir=/data/mysql --initial --initialize-insecure 2015-06-24T06:05:05.533588Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2015-06-24T06:05:05.533627Z 0 [ERROR] Aborting ~~~ 因此,需要先确保 datadir 目标目录下是空的,避免误操作破坏已有数据。 另外,在初始化时如果加上 –initial-insecure,则会创建空密码的 root@localhost 账号,否则会创建带密码的 root@localhost 账号,密码直接写在 log-error 日志文件中(在5.6版本中是放在 ~/.mysql_secret 文件里,更加隐蔽,不熟悉的话可能会无所适从) ~~~ [yejr@imysql.com]#./bin/mysqld --user=mysql --basedir=/opt/17173_install/mysql-5.7.7-rc-linux-glibc2.5-x86_64/ --datadir=/data/mysql --initial 2015-06-24T06:14:31.458905Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path. ~~~ 初始化完毕后,如果没使用新版本的客户端登入,还会报告类似下面的错误: ~~~ mysql -uroot -p Enter password: ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords. ~~~ 上面的错误提示意思是需要用当前版本的客户端登入,因为新用户登入后需要立刻修改密码,否则无法继续后续的工作: ~~~ [(root@imysql.com)]>use mysql ERROR 1820 (HY000): You must SET PASSWORD before executing this statement [(root@imysql.com)]>set password = password('abcd'); Query OK, 0 rows affected, 1 warning (0.00 sec) ~~~ 修改完密码后,就可以继续使用旧版本的客户端工具了。 下一期,我们继续讲讲5.7的其他新特性。