Linux server to open MySQL remote connection permissions

Source: Internet
Author: User

For security reasons root accounts are generally accessible only locally, but you may need to open root remote access permissions during development. The following are the basic steps:


1, login to MySQL, for root remote access authorization, execute the following command:

1.1, Change Table method :

Your account may not be allowed to log in remotely, only in localhost. This time as long as the computer in localhost, login mysql, change the "MySQL" Database in the "User" table in the "host" item, from "localhost" renamed "%"

The code is as follows Copy Code

X:>mysql-u Root-pvmware

mysql> use MySQL;
mysql> Update user Set host = '% ' where user = ' root ';
Mysql> Select Host, user from user;

mysql> flush Privileges;


Note:mysql> flush privileges; Make the changes take effect.

1.2. Authorization Law:

For example, you want to myuser use MyPassword to connect to a MySQL server from any host.

The code is as follows Copy Code

Mysql> grant all privileges in *.* to ' myuser ' @ '% ' identified by ' MyPassword ' with GRANT OPTION;

If you want to allow the user to connect to the MySQL server from the IP-192.168.1.3 host, and use MyPassword as the password myuser

The code is as follows Copy Code
Mysql> grant all privileges in *.* to ' myuser ' @ ' 192.168.1.3 ' identified by ' MyPassword ' with GRANT OPTION;

"%" in the first sentence means that any host can log on to the server remotely. If you want to restrict access to only one machine, replace it with the appropriate IP, such as:

The code is as follows Copy Code


GRANT all privileges on *.* to root@ "172.168.193.25" identified by "root";

The second sentence means reloading the permission data from the grant table in the MySQL database. Because MySQL puts all the permissions in the cache, it needs to be reloaded after the changes are done.

2, modify/etc/mysql/my.cnf, need root user rights. Found in the file:

The code is as follows Copy Code

Bind-address = 127.0.0.1

Comment It out and save it.

3, restart the MySQL server. Execute a few of the following commands:

The code is as follows Copy Code

#/usr/bin/mysqladmin-u Root-p shutdown

#/usr/bin/mysqld_safe &

If Mysqladmin and Mysql_safe are not in the/usr/bin directory, you can find them through the Whereis command, for example:

The code is as follows Copy Code

# Whereis Mysqladmin

Mysqladmin:/usr/bin/mysqladmin/usr/share/man/man1/mysqladmin.1.gz

After performing the three steps above, you can connect to the database through a remote machine.

Finally made a lot of summary sentence

One more thing, it's fire-proof.

Modify Firewall

  code is as follows copy code

Iptables-i Input-p TCP--dport 3306-j ACCEPT

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.