MySQL 如何在centos中启用mysql的远程访问?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23733734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:31:44  来源:igfitidea点击:

How to enable remote access of mysql in centos?

mysqlcentos

提问by Puneet

My apache is running on 8113port instead of 80.

我的 apache 运行在8113端口而不是80.

I want to access my mysql Database remotely. I have tried following steps.

我想远程访问我的 mysql 数据库。我试过以下步骤。

Bind-address XXX.XX.XX.XXX in /etc/my.cnf
Create Database 
and run the command 
GRANT ALL PRIVILEGES ON *.* TO  'USERNAME'@'IP'  IDENTIFIED  BY  'PASSWORD';

But not able to connect. I am using heidi sql to connect.

但无法连接。我正在使用 heidi sql 进行连接。

采纳答案by matanco

so do the following edit my.cnf:

所以做以下编辑my.cnf:

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = xxx.xxx.xxx.xxx
# skip-networking

after edit hit service mysqld restart

编辑命中后 service mysqld restart

login into mysql and hit this query:

登录到 mysql 并点击这个查询:

GRANT ALL ON foo.* TO bar@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'PASSWORD';

GRANT ALL ON foo.* TO bar@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'PASSWORD';

thats it make sure your iptables allow connection from 3306 if not put the following:

如果不输入以下内容,请确保您的 iptables 允许来自 3306 的连接:

iptables -A INPUT -i lo -p tcp --dport 3306 -j ACCEPT

iptables -A INPUT -i lo -p tcp --dport 3306 -j ACCEPT

iptables -A OUTPUT -p tcp --sport 3306 -j ACCEPT

iptables -A OUTPUT -p tcp --sport 3306 -j ACCEPT

回答by Alexander T

Bind-address XXX.XX.XX.XXX in /etc/my.cnf

/etc/my.cnf 中的绑定地址 XXX.XX.XX.XXX

comment line:

评论行:

skip-networking

跳过网络

or

或者

skip-external-locking

跳过外部锁定

after edit hit service mysqld restart

编辑命中后 service mysqld restart

login into mysql and hit this query:

登录到 mysql 并点击这个查询:

GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'%' IDENTIFIED BY 'password';

FLUSH PRIVILEGES;
quit;

add firewall rule:

添加防火墙规则:

iptables -I INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

回答by Md Nazrul Islam

In case of Allow IP to mysql server linux machine. you can do following command--

在允许 IP 到 mysql 服务器 linux 机器的情况下。您可以执行以下命令-

 nano /etc/httpd/conf.d/phpMyAdmin.conf  and add Desired IP.

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   Order allow,deny
   allow from all
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>

    Require ip 192.168.9.1(Desired IP)

</RequireAny>
   </IfModule>
 <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     #Allow from All

     Allow from 192.168.9.1(Desired IP)

</IfModule>

And after Update, please restart using following command--

更新后,请使用以下命令重新启动--

sudo systemctl restart httpd.service