[root@HKBO ~]# find / -name mysql
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
.........
/app/soft/mysql
/app/soft/mysql/bin/mysql
/app/soft/mysql/include/mysql
/var/lib/mysql
/var/spool/mail/mysql
/opt/data/mysql
/home/mysql
#移除旧版mysql的路径及其文件
[root@HKBO ~]# rm -rf /var/lib/mysql
#考虑到配置文件的为旧版,直接用5.6.12版的缺省配置文件覆盖
[root@HKBO ~]# cp /app/soft/mysql/support-files/my-default.cnf /etc/my.cnf
[root@HKBO ~]# grep -v ^# /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#重启mysql
[root@HKBO ~]# service mysqld stop
Shutting down MySQL..[ OK ]
[root@HKBO ~]# service mysqld start
Starting MySQL.[ OK ]
[root@HKBO ~]# mysql -uroot -p --secure_auth=off
Enter password:
mysql> select user,host,password from mysql.user;
+------+--------------+------------------+ # Author : Leshami
| user | host | password | # Blog :
+------+--------------+------------------+
| root | localhost | 7ca9a8e40dd1bf23 | #可以看到加密后的密码为16bit
+------+--------------+------------------+
mysql> set password for 'root'@'localhost'=password('Mysql66');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select user,host,password from mysql.user where user='root';
+------+--------------+------------------+
| user | host | password |
+------+--------------+------------------+
| root | localhost | 5614c1a44e6b0c87 | #更新后还是16bit
+------+--------------+------------------+
#接下来尝试清空root密码
mysql> update mysql.user set password='' where user='root' and host='localhost';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
#再一次重启mysql
[root@HKBO ~]# service mysqld stop
Shutting down MySQL.[ OK ]
[root@HKBO ~]# service mysqld start
Starting MySQL.[ OK ]
#接下来使用mysqladmin修改密码
[root@HKBO ~]# mysqladmin -u root password 'xxx'
#此时可以成功登陆,且密码的密文明显变长,至此问题解决
[root@HKBO ~]# mysql -uroot -p
Enter password:
mysql> select user,password,host from mysql.user;
+------+-------------------------------------------+--------------+
| user | password | host |
+------+-------------------------------------------+--------------+
| root | *3D56A309CD04FA2EEF181462E59011F075C89548 | localhost |
+------+-------------------------------------------+--------------+
4、小结
a、绝大多数情况下,MySQL缺省的my.cnf不靠谱,根据情况都需要适度修改。
b、在安装MySQL之前应先检查当前主机是否存在旧版以及多实例(此次由于非生产环境,所以疏忽导致了这个问题)
c、根据错误提示来定位故障原因,如此次的关键字为secure_auth
d、理解有关secure_auth,old_passwords,skip-secure-auth参数的作用及其影响