Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 15:19:05
Original
1262 people have browsed it

今天在实验室的服务器上安装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>
Copy after login

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

然后启动MySQL服务

<code>sudo /etc/init.d/mysql start
</code>
Copy after login

打开MySQL

<code>sudo mysql -uroot -p
</code>
Copy after login

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

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

执行

<code>use information_schema
select * from user_privileges;
</code>
Copy after login

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

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

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

<code>sudo /etc/init.d/mysql restart
</code>
Copy after login

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!