乌班图 mysql5.7 ERROR 1698 (28000): Access denied for user 'root'@'localhost'

看了很多解决mysql错误的博客,这篇最靠谱 所以进行了转载

# 安装mysql服务
sudo apt-get install mysql-server
# 安装客户端
sudo apt install mysql-client
# 安装依赖
sudo apt install libmysqlclient-dev
# 检查状态
sudo netstat -tap | grep mysql
#-----------------------------------------------------------------------------------------------------

$ sudo su
# mysql
mysql>
mysql> select user, plugin from mysql.user;
+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
| mysql.session    | mysql_native_password |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
mysql> flush privileges;
mysql> exit
Bye
# exit
$ sudo /etc/init.d/mysql restart
$ mysql -uroot -p

mysql>
#-----------------------------------------------------------------------------------------------------

# 修改配置文件,注释掉bind-address = 127.0.0.1
$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

# 保存退出,然后进入mysql服务,执行授权命令:
$ mysql -uroot -p

mysql> grant all on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
$ sudo /etc/init.d/mysql restart

---------------------
作者:lynnyq
来源:CSDN
原文:https://blog.csdn.net/lynnyq/article/details/80296137
版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(乌班图 mysql5.7 ERROR 1698 (28000): Access denied for user 'root'@'localhost')