Set the root permission for mysql remote connection _ MySQL

Source: Internet
Author: User
Set the root permission for mysql remote connection bitsCN.com

You may have encountered this problem when remotely connecting to mysql. the root user cannot connect to mysql remotely, but can only connect locally and reject the connection.

You must create a database account that allows remote logon to perform database operations.

The method is as follows:

By default, the user permissions in the MYSQL system table user of the mysql database only provide localhost local login;

You must change the permissions to remotely connect to the MYSQL database.

You can confirm the problem by using the following methods:

Root # mysql-h localhost-uroot-p

Enter password :******

Welcome to the MySQL monitor. Commands end with; or/g.

Your MySQL connection id is 4 to server version: 4.0.20a-debug

Type 'help; 'or'/h' for help. type'/C' to clear the buffer.

Mysql> use mysql; (this DB stores various MySQL configuration information)

Database changed

Mysql> select host, user from user; (view user permissions)

Mysql> select host, user, password from user;
+ ----------- + ------ + --------------------------------------------- +
| Host | user | password |
+ ----------- + ------ + --------------------------------------------- +
| Localhost | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| Localhost |
+ ----------- + ------ + --------------------------------------------- +
4 rows in set (0.01 sec)

From this we can see that it can only be accessed as a localhost.
Solution:
Mysql> Grant all privileges on *. * to 'root' @ '%' identified by 'dm001' with grant option;
(% Indicates all external Machines. if a specific machine is specified, Change % to the corresponding machine name; 'root' indicates the user name to be used ,)
Mysql> flush privileges; (run this statement to take effect, or restart MySQL)
Query OK, 0 rows affected (0.03 sec)

View again ..

Mysql> select host, user, password from user;
+ ----------- + ------ + --------------------------------------------- +
| Host | user | password |
+ ----------- + ------ + --------------------------------------------- +
| Localhost | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| 127.0.0.1 | root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| Localhost |
| % | Root | * 4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
+ ----------- + ------ + --------------------------------------------- +
4 rows in set (0.01 sec)

We can see that a new user has been added.

Check whether the mysqld listening mode is set to only listen to localhost,

Use netstat to check if yes. Find the mysql configuration file my. cnf and change the bind address to the real IP address of the machine.

You can also comment out bind address directly. Restart is required to take effect.

Exit and try the effect ....

Now you can successfully log on ..

This article is from the "jie blog"

BitsCN.com

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.