ubuntu 16.04 在apt直接安装mysql 5.7过程中没有询问输入密码,安装完成后后无法用普通账号登陆mysql,即使用了mysql_safe启动修改密码也无效
但是用sudo mysql -u root 的话,却可以不提示密码直接登陆。
经过查找后,找到老外的解决方法。。。实际上和我的操作大同小异,反正成功了就好。
1 – First, connect in sudo mysql
1
sudomysql-uroot
2 – Check your accounts present in your db
1
SELECTUser,HostFROMmysql.user;
+——————+———–+
| User | Host |
+——————+———–+
| admin | localhost |
| debian-sys-maint | localhost |
| magento_user | localhost |
| mysql.sys | localhost |
| root | localhost |
3 – Delete current root@localhost account
1
mysql>DROPUSER'root'@'localhost';
Query OK, 0 rows affected (0,00 sec)
4 – Recreate your user
1
mysql>CREATEUSER'root'@'%'IDENTIFIEDBY'';
Query OK, 0 rows affected (0,00 sec)
5 – Give permissions to your user (don’t forget to flush privileges)
1
mysql>GRANTALLPRIVILEGESON*.*TO'root'@'%';
Query OK, 0 rows affected (0,00 sec)
1
mysql>FLUSHPRIVILEGES;
Query OK, 0 rows affected (0,01 sec)
6 – Exit mysql and try to reconnect without sudo