我已经在我的本地机器上安装了MySQL Community Edition 5.5,我想允许远程连接,这样我就可以从外部源连接。
我该怎么做呢?
我已经在我的本地机器上安装了MySQL Community Edition 5.5,我想允许远程连接,这样我就可以从外部源连接。
我该怎么做呢?
当前回答
请按照下面提到的步骤来设置MySQL用户的通配符远程访问。
(1) Open cmd. (2) navigate to path C:\Program Files\MySQL\MySQL Server 5.X\bin and run this command. mysql -u root -p (3) Enter the root password. (4) Execute the following command to provide the permission. GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'IP' IDENTIFIED BY 'PASSWORD'; USERNAME: Username you wish to connect to MySQL server. IP: Public IP address from where you wish to allow access to MySQL server. PASSWORD: Password of the username used. IP can be replaced with % to allow user to connect from any IP address. (5) Flush the previleges by following command and exit. FLUSH PRIVILEGES; exit; or \q
其他回答
在完成以上所有操作后,我仍然无法以根用户远程登录,但是telnet到3306端口确认MySQL正在接受连接。
我开始查看MySQL中的用户,并注意到有多个具有不同密码的根用户。
select user, host, password from mysql.user;
所以在MySQL中,我再次为root设置了所有密码,我最终可以以root身份远程登录。
use mysql;
update user set password=PASSWORD('NEWPASSWORD') where User='root';
flush privileges;
在我的情况下,我试图连接到一个远程mysql服务器在cent操作系统。在经历了许多解决方案(授予所有特权,删除ip绑定,启用网络)后,问题仍然没有得到解决。
事实证明,在寻找各种解决方案时,我遇到了iptables,这让我意识到mysql端口3306不接受连接。
下面是关于我如何检查和解决这个问题的一个小说明。
检查端口是否接受连接:
telnet (mysql server ip) [portNo]
添加ip表规则,允许端口上的连接:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
不建议在生产环境中这样做,但如果您的iptables没有正确配置,添加规则可能仍然不能解决问题。在这种情况下,应该做以下工作:
service iptables stop
希望这能有所帮助。
只是F.Y.I 我为这个问题苦恼了好几个小时。最后,我打电话给我的主机提供商,发现在我使用云服务器的情况下,在1and1的控制面板中,他们有一个二级防火墙,你必须克隆并添加端口3306。一加进去我就直接进去了。
请按照下面提到的步骤来设置MySQL用户的通配符远程访问。
(1) Open cmd. (2) navigate to path C:\Program Files\MySQL\MySQL Server 5.X\bin and run this command. mysql -u root -p (3) Enter the root password. (4) Execute the following command to provide the permission. GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'IP' IDENTIFIED BY 'PASSWORD'; USERNAME: Username you wish to connect to MySQL server. IP: Public IP address from where you wish to allow access to MySQL server. PASSWORD: Password of the username used. IP can be replaced with % to allow user to connect from any IP address. (5) Flush the previleges by following command and exit. FLUSH PRIVILEGES; exit; or \q
检查远程服务器是否允许通配符访问端口3306:
sudo lsof -i -P -n | grep监听
不应该是这样的:
mysqld 23083 mysql 21u IPv4 145900142 0t0 TCP 127.0.0.1:3306(听)
在这种情况下,我们需要更新/etc/mysql/mysql.conf.d/mysqld.cnf或/etc/mysql/mariadb.conf.d/50-server.cnf:
Bind-address = 127.0.0.1——> 0.0.0.0
然后重新启动mysql "sudo service mysql restart"
为了从客户端测试mySQL连接:
Nc -vz <host_address> 3306