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.
,