本地mysql连接linux虚拟机mysql 连不上得解决方案

1.进入虚拟机mysql

[root@localhost ~]# mysql -u root -p
2.进入mysql 目录 并查看mysql目录是否是本地查看
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> select 'host' from user where user='root';
+------+
| host |
+------+
| host |
+------+
1 row in set (0.24 sec)

3.host则为本地可以访问,接下来我们改为外网访问

mysql> update user set host='%' where user='root';
Query OK, 1 row affected (2.41 sec)
Rows matched: 1  Changed: 1  Warnings: 0

4.退出mysql,重启服务

mysql> exit;
Bye
[root@localhost ~]# service mysqld stop;
Shutting down MySQL............................. SUCCESS! 
[root@localhost ~]# service mysql start;
Redirecting to /bin/systemctl start mysql.service

5.启动成功后,本地mysql连接虚拟机,OK!

猜你喜欢

转载自blog.csdn.net/m0_37974328/article/details/80677689