ubuntu 16.04 安装mysql 5.7后无法用普通账号登陆mysql

ubuntu 16.04 在apt直接安装mysql 5.7过程中没有询问输入密码,安装完成后后无法用普通账号登陆mysql,即使用了mysql_safe启动修改密码也无效
但是用sudo mysql -u root 的话,却可以不提示密码直接登陆。
经过查找后,找到老外的解决方法。。。实际上和我的操作大同小异,反正成功了就好。

1 – First, connect in sudo mysql

2 – Check your accounts present in your db

+——————+———–+
| User | Host |
+——————+———–+
| admin | localhost |
| debian-sys-maint | localhost |
| magento_user | localhost |
| mysql.sys | localhost |
| root | localhost |

3 – Delete current root@localhost account

Query OK, 0 rows affected (0,00 sec)
4 – Recreate your user

Query OK, 0 rows affected (0,00 sec)
5 – Give permissions to your user (don’t forget to flush privileges)

Query OK, 0 rows affected (0,00 sec)

Query OK, 0 rows affected (0,01 sec)
6 – Exit mysql and try to reconnect without sudo

Leave a Comment