问题现象:本机连接远程环境的mysql数据库报错,提示本机ip无法连接到mysql服务器。
问题原因:本机对远程mysql数据库没有访问权限。
解决方法:在远程mysql数据库添加本机ip的访问权限:
1、登陆远程mysql,这里的用户名和密码都是root
[root@izwz932ypmamm80m434qqyz ~]# mysql -uroot -proot Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 20 Server version: 5.5.55-log MySQL Community Server (GPL) by Atomicorp Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 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.
2、进入mysql数据库,查询用户表
mysql> use mysql; Database changed mysql> select user,password,host from user; +------+-------------------------------------------+-------------------------+ | user | password | host | +------+-------------------------------------------+-------------------------+ | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | localhost | | root | | izwz932ypmamm80m434qqyz | | root | | 127.0.0.1 | | root | | ::1 | | | | localhost | | | | izwz932ypmamm80m434qqyz | +------+-------------------------------------------+-------------------------+ 6 rows in set (0.00 sec)
3、添加本机ip(这里为117.149.10.46),用户名密码还是设置为root
mysql> grant all privileges on *.* to root@"117.149.10.46" identified by "root"; Query OK, 0 rows affected (0.00 sec) mysql> select user,password,host from user; +------+-------------------------------------------+-------------------------+ | user | password | host | +------+-------------------------------------------+-------------------------+ | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | localhost | | root | | izwz932ypmamm80m434qqyz | | root | | 127.0.0.1 | | root | | ::1 | | | | localhost | | | | izwz932ypmamm80m434qqyz | | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | 117.149.10.46 | +------+-------------------------------------------+-------------------------+ 7 rows in set (0.00 sec)
4、重新加载mysql的访问权限
mysql>flush privileges;
本机重新连接远程mysql成功。