Heim  >  Artikel  >  Datenbank  >  解决不能远程连接Linux服务器上MySQL的问题

解决不能远程连接Linux服务器上MySQL的问题

WBOY
WBOYOriginal
2016-06-07 15:19:051262Durchsuche

今天在实验室的服务器上安装MySQL,装好后却发现远程的电脑无法连接到MySql服务器。服务器操作系统是Ubuntu 14.04。于是在网上查了些资料,折腾了半天后终于搞定了,下面是具体的步骤。 安装好MySQL后,修改如下文件 sudo vim /etc/mysql/my.cnf 找到 bind-a

今天在实验室的服务器上安装MySQL,装好后却发现远程的电脑无法连接到MySql服务器。服务器操作系统是Ubuntu 14.04。于是在网上查了些资料,折腾了半天后终于搞定了,下面是具体的步骤。


安装好MySQL后,修改如下文件

<code>sudo vim /etc/mysql/my.cnf
</code>

找到bind-address = 127.0.0.1,将绑定地址改成0.0.0.0或者直接将该行注释掉

然后启动MySQL服务

<code>sudo /etc/init.d/mysql start
</code>

打开MySQL

<code>sudo mysql -uroot -p
</code>

输入密码,进入MySQL命令行,在MySQL命令行中执行下列命令

<code>grant all PRIVILEGES on *.* to root@'%' identified by 'onePassword';
</code>

执行

<code>use information_schema
select * from user_privileges;
</code>

如果查询有如下的结果:'root'@'%',说明mysql已经授权远程连接。
退出MySQL命令行,在终端中执行

<code>iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
</code>

将3306端口添加到iptables中。
最后执行以下命令,重新启动MySQL服务

<code>sudo /etc/init.d/mysql restart
</code>

然后其他的电脑就可以远程连接服务器上的MySLQ了,问题虽然不大,也不是第一次遇到了,但是每次都要花费很多的时间才能解决,做个小记录,以防今后再碰到类似的问题,又要从头开始。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn