当前位置: 移动技术网 > IT编程>数据库>Mysql > 解决MySQL无法远程连接的方法

解决MySQL无法远程连接的方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

mysql远程连接无法打开解决办法


1、改表法

请使用mysql管理工具,如:sqlyog enterprise、navicate mysql

可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑使用mysql管理工具登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"


2、 授权法。

a:你想mysql账户myuser使用密码mypassword从任何主机连接到mysql服务器的话,那就在mysql命令行下输入:
grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword' with grant option;

若上面那条命令还没有奏效,那就使用下面的命令,一定成功!

如果你想允许想mysql账户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码,那就在mysql命令行下输入:

grant all privileges on *.* to 'myuser'@'192.168.1.3' identified by 'mypassword' with grant option;

以下是其它网友的补充:

在远程主机上,我开启了mysql 服务,用 phpmyadmin 可以打开,比如说用户名为 root,密码为 123456。不过用 mysql 客户端远程连接时却报了错误,比如 mysql-front 报了如下错误。

access denied for user ‘root'@'121.42.8.33′(using password:yes)

2015430171226837.jpg (752×512)

比较奇怪,phpmyadmin 可以正常访问,而 mysql-front 为什么无法连接呢?可能的原因,应该就是 ip 限制了,phpmyadmin在连接时使用的是localhost,而我们访问页面才使用的远程主机的 ip,而 mysql-front 连接的是远程主机。

解决方法如下,我们需要新建一个用户,然后授予所有 ip 可以访问的权限就好啦。

在下面的 sql 语句中,username 即为用户名,password 为你要设置的密码:

create user 'username'@'localhost' identified by 'password';

grant all privileges on *.* to 'username'@'localhost' with grant option;

create user 'username'@'%' identified by 'password';

grant all privileges on *.* to 'username'@'%' with grant option;
 
create user 'username'@'localhost' identified by 'password';
 
grant all privileges on *.* to 'username'@'localhost' with grant option;
 
create user 'username'@'%' identified by 'password';
 
grant all privileges on *.* to 'username'@'%' with grant option;

通过执行以上语句,便创建了一个用户名为 username,密码为 password 的新账户,再用新账号登录,就可以连接成功啦。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网