Enable remote logon for mysql

Source: Internet
Author: User
Sometimes, because the database and website are placed in different IP Addresses During website construction, mysql needs to be remotely connected using a program, while mysql is secure, by default, you cannot connect remotely or locally. In this case, you need to modify the settings. The following describes the methods. Enter the cmd command mode. Mysql-hloc

Sometimes, because the database and website are placed in different IP Addresses During website construction, mysql needs to be remotely connected using a program, while mysql is secure, by default, you cannot connect remotely or locally. In this case, you need to modify the settings. The following describes the methods. Enter the cmd command mode. Mysql-h loc

Sometimes, because the database and website are placed in different IP Addresses During website construction, mysql needs to be remotely connected using a program, while mysql is secure, by default, you cannot connect remotely or locally. In this case, you need to modify the settings. The following describes the methods.

Enter the cmd command mode.

Mysql-h localhost-u mysql-p

Enter password :******

Connect to the database.

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

Database changed

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

+ ------------- + ------- +

| Host | user |

+ ------------- + ------- +

| Localhost |

| Localhost | root |

| Localhost |

| Localhost | mysql |

+ ------------- + ------- +

6 rows in set (0.02 sec)

From this we can see that it can only be accessed as a localhost.

Mysql> Grant all privileges on *. * to 'root' @ '%' identified by 'Password' 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, the password must be changed to the root password)

Mysql> flush privileges)

Query OK, 0 rows affected (0.03 sec)

Mysql> select host, user from user; (view user Permissions again)

+ ------------- + ------- +

| Host | user |

+ ------------- + ------- +

| % | Mysql |

| % | Root |

| Localhost |

| Localhost | root |

| Localhost |

| Localhost | mysql |

+ ------------- + ------- +

Mysql> exit

Try again now: Check whether you can log on to the remote cmd. If you can log on, you can use the code to connect to it.

Note that the user permission table is in the db table of the mysql database, which records in detail which users have permissions to operate on which databases, this is important for managing multiple users.

,

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.