今天被这个问题弄得很烦,查了无数资料终于解决,特地记录一下。 亲测本方法针对使用在物理机win10+虚拟机ubuntu20.04.4+命令行安装mysql(截至2020.8.26,命令行sudo apt-get install mysql
安装的sql为8.0.21版本)+桥接模式 的环境下,
可以解决
1.access denied for user ‘root’@‘ip’
2.access denied for user ‘root’@‘ip’ (using password:YES)
3.access denied for user ‘root’@‘ip’ (using password:NO)
4.access denied for user ‘root’@‘localhost’
5.access denied for user ‘root’@localhost’(using password:YES)
6.access denied for user ‘root’@localhost’(using password:NO)
7.2003-Can’t connect to MySQL server on ‘ip’ (10061 “Unknown error”)
8.1130-Host ‘ip’ is not allowed to connect to this MySQL server等问题。而且解决的方式是相同的。
解决该问题之前,请确保你的ubuntu20.04.4虚拟机防火墙处于关闭状态,且物理机win10能够ping通该虚拟机。
以下为解决方案:
1.以root权限运行service mysql stop
2.修改配置文件 vim /etc/mysql/mysql.conf.d/mysqld.cnf
,将bind-address =127.0.0.1用#注释掉,并且在最后一行添加skip-grant-tables
3.service mysql restart
,并且使用mysql -uroot -p
进入mysql,这里不需要输入密码,因为在2中跳过了密码验证,再use mysql;
4.update mysql.user set authentication_string='' where user = 'root';
设置空密码,退出mysql。
5. vim /etc/mysql/mysql.conf.d/mysqld.cnf
把步骤2中添加的最后一行skip-grant-tables
注释掉。
6. service mysql restart
,重启mysql服务,并且使用mysql -uroot -p
进入mysql,这里直接enter就行不需要输入密码,因为在4中设置密码为空了。
7. use mysql;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxx';
xxx为密码。
8. 大功告成,退出mysql,service mysql restart
。此时可以在ubuntu系统中使用 mysql -uroot -pxxx
进入mysql,且同时在物理机上可以通过ip地址连接虚拟机上的mysql。
本人在物理机A,B上分别有虚拟机a,b。a,b均为桥接模式,A(有线网络),B(wifi)在同一局域网下。在虚拟机a,b中操作以上步骤后,可以在A上使用navicat premium 12连接a和b的mysql,并且a,b既可以连接自身的mysql,也能使用
mysql -h主机地址 -u用户名 -p用户密码
相互连接