[英]Unable to connect mysql using ip address
I try to connect my db using host address as my ip address 203.199.209.**,but not able to connect db.if i try to connect my db using host address as localhost it connected successfully. 我尝试使用主机地址作为我的IP地址203.199.209。**连接数据库,但是无法连接db.if我尝试使用主机地址作为localhost连接我的数据库成功连接。 How to solve this issue?
如何解决这个问题?
MySQL grants access based on which host you are connecting from. MySQL根据您连接的主机授予访问权限。
Run this command as root
: 以
root
身份运行此命令:
SELECT user, host FROM mysql.user;
These are the users which exist on your server. 这些是服务器上存在的用户。 Notice the
host
column. 注意
host
列。
In short, a user is defined as both a user name ( user
) and a point of connection ( host
). 简而言之,将用户定义为用户名(
user
) 和连接点( host
)。 When you access your server as localhost
, you actually login as some_user@localhost
. 当您以
localhost
身份访问服务器时,实际上是以some_user@localhost
身份登录。 On the other hand, when you access the sever via its IP address, you actually login as some_user@your.ip.address.here
. 另一方面,当您通过服务器的IP地址访问服务器时,您实际上以
some_user@your.ip.address.here
登录。 I guess the latter does not exist on your server. 我猜后者在您的服务器上不存在。
You may want to create a new user such as some_user@your.ip.address.here
or some_user@%
(the percent sign is a wildcard; here, it means "any host"): 您可能要创建一个新用户,例如
some_user@your.ip.address.here
或some_user@%
(百分号是通配符;在这里,它表示“任何主机”):
CREATE USER 'some_user'@'your.ip.address.here' IDENTIFIED BY 'your_password';
GRANT ALL ON your_database.* to 'some_user'@'your.ip.address.here';
If you wish to dig further, see this manual page for more details about MySQL access control, and this page for the CREATE USER
syntax. 如果您想进一步研究,请参见本手册页以获取有关MySQL访问控制的更多详细信息,以及该页的
CREATE USER
语法。
[edit] [编辑]
Obviously, as suggested by others, you first need to make sure your server listens to this IP address (203.199.209.**). 显然,按照其他人的建议,您首先需要确保您的服务器侦听此IP地址(203.199.209。**)。 But if this were not already the case, you should get the following error:
但是,如果不是这种情况,您应该得到以下错误:
ERROR 2003 (HY000): Can't connect to MySQL server on '203.199.209.**' (111)
错误2003(HY000):无法连接到203.199.209。**上的MySQL服务器(111)
The error you are getting definitely indicates a permission issue. 您收到的错误肯定表示权限问题。
For mysql-5.7.15-winx64 (Windows Version), login as "root" user and run the following queries in MYSQL: 对于mysql-5.7.15-winx64(Windows版),以“ root”用户身份登录并在MYSQL中运行以下查询:
CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
CREATE USER 'user'@'%' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
and then Re-start your MYSQL DB. 然后重新启动您的MYSQL DB。
For this version of MYSQL DB no changes are required in "my-default.ini" located in the same location as "bin" folder. 对于此版本的MYSQL DB,不需要在与“ bin”文件夹相同位置的“ my-default.ini”中进行任何更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.