Enable the mysqld remote connection permission for centos

Source: Internet
Author: User

Solution to MySQL remote connection failure (centos)
(1) Stop the MySQL service first.
#/Etc/init. d/mysqld stop
(2) view the MySQL configuration file
# Vi/etc/My. CNF
Pay special attention to the following two items: bind_address and skip_networking. bind_address cannot be 127.0.0.1; otherwise, it can only be connected locally and skip_networking cannot appear, otherwise, only the UNIX socket is accepted and the TCP socket service is not available. We recommend that you comment out bind_address and skip_networking directly.
(3) restart the MySQL Service
#/Etc/init. d/mysqld start
(4) authorize the user to allow remote access by the specified user. The simplest way is to set the host of the user in the User table in the MySQL database to %, that is, allow remote access from any IP address.

# Mysql-u root-ppassword // enter the MySQL Console
# Mysql> use MySQL;
# Mysql> Update user set host = '%' where user = 'root'; // you can skip this error when executing this command.

# Mysql> flush privileges;
# Mysql> select host, user from user; // check whether '%' is inserted into the database
# Mysql> \ q
(5) In general, remote access can be satisfied at this time, but some systems still need to check firewall settings and IP access policies, in case that the system cannot remotely access MySQL due to network access restrictions
For centos systems, it is best to check iptables settings. The procedure is as follows:
5.1 suspend the iptables service
# Service iptables stop
5.2 view the iptables configuration file
# Vi/etc/sysconfig/iptables
5.3 you may see the following content
: Output accept [1009120: 257185920]
-A input-p tcp-m tcp-dport 3306-J accept
#-A input-s 118.144.89.18-p tcp-m tcp-dport 3306-J accept
#-A input-s 123.127.177.239-p tcp-m tcp-dport 3306-J accept
We recommend that you open port 3306 directly, instead of specifying an IP address to access port 3306.
5.4 restart the iptables service
# Service iptables start

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.