1.问题描述
在ubuntu上安装mysql后,由于没有设置密码,空密码登录并且已经导入了数据库,这时不能使用mysql_secure_installation初始化数据库,修改密码,会导致导入的数据库文件丢失。并且使用空密码进入数据库使用set,alter,update语句修改均不生效:
mysql> set password = password('xxxxxxxxx');
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> alter user 'root'@'localhost' identified by 'xxxxxxxxc';
Query OK, 0 rows affected (0.00 sec)
mysql> update mysql.user set authentication_string = password('xxxxxxxxxxxx') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
虽然上面update修改显示生效了,但依然能用空密码登录。怪事,于是开始了“踩坑之路”。
尝试解决:使用mysql自带默认用户登录修改密码
root@iZ238ot3od7Z:~# cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts.