主机:win11
虚拟机:centos 7
mysql:8.0.35
最开始的问题是ping不通,我的虚拟机选择的是nat模式,经检查发现VMnet8的ip地址与虚拟机的ip地址不在同一网络上(即其前三组地址要相同)。因为我使用的不是pro版vmware,所以无法使用虚拟网络编辑器,只能重开几次让二者在同一网络上。在同一网络上时结果如下:
在能ping通了之后还是连接不上,会报错:
ERROR 1045 (28000): Access denied for user 'ODBC'@'192.168.242.1' (using password: YES)
之后,我又去虚拟机上把root的权限改为可远程访问。在这一步,要在user表中进行,输入:
mysql> use mysql
然后输入两边如下语句:
GRANT ALL ON *.* TO 'root'@'%';
之后查看权限发现root用户已经可以进行远程访问了
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | $A$005$F&7rvw\?%9pv%4ZmQWylr9sGeFMmFDTEbDKOvVyyVgdNpgFPCELnO7p0 | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
再次尝试连接数据库发现依然报错
ERROR 1045 (28000): Access denied for user 'ODBC'@'192.168.242.1' (using password: YES)
后来思考一下发现是因为mysql服务器上是没有ODBC这个用户的,所以在访问时要加上用户的名称
C:\Windows\System32>mysql -h192.168.242.128 -P3306 -uroot -p123456
最后访问成功了
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.35 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.