In many cases, remote access to mysql is required, but the root user can only connect locally. To achieve remote access to the mysql database on your pc, you must open another account. First, run the mysql Command on MySQLServer to enter the mysql command mode. The SQL code mysqlusemysql; mysqlGRANTALLON *. * TOadmin @ %
In many cases, remote access to mysql is required, but the root user can only connect locally. To achieve remote access to the mysql database on your pc, you must open another account. First, run the MySQL command ON the mysql Server TO enter the mysql command mode. The SQL code mysqlusemysql; mysql GRANT ALL ON *. * TO admin @ '%'
In many cases, remote access to mysql is required, but the root user can only connect locally. To achieve remote access to the mysql database on your pc, you must open another account.
First, on the MySQL Server:
Run the mysql command to enter the mysql command mode,
SQL code
- Mysql> use mysql;
- Mysql> grant all on *. * TO admin @ '%' identified by 'admin' with grant option;
- # Allow any IP address (% above) to access the MySQL Server using the admin account and password (admin.
Remote login:
- On another MySQL client (pc with mysql package installed, either windows or linux)
Run the following command:
SQL code
- Mysql-h172.21.5.29-uadmin-padmin.
- // 172.21.5.29 is the IP address of MySQL Server, and admin is the remote access account just set on 172.21.5.29.
Note:
If the preceding command is complete, you are running localhost locally. Execute:
SQL code
- Mysql-hlocalhost-uadmin-padmin
The result is failed. The above % does not include localhost, so you must add the following command:
Mysql> grant all on *. * TO admin @ 'localhost' identified by 'admin' with grant option;
This command can ensure that you can log on locally as an admin account.
Original blog address: http://www.cnblogs.com/xd502djj/archive/2011/04/01/2001826.html
If the above information is not clear enough, you can refer to the following content:
MySQL remote access permission, enabling remote connection
1. log on to the mysql database
Mysql-u root-p
View the user table www.2cto.com
Mysql> use mysql;
Database changed
Mysql> select host, user, password from user;
+ -------------- + ------ + --------------------------------------------- +
| Host | user | password |
+ -------------- + ------ + --------------------------------------------- +
| Localhost | root | * A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | * A731AEBFB621E354CD41BAF207D884A609E81F5E |
+ -------------- + ------ + --------------------------------------------- +
2 rows in set (0.00 sec)
You can see the created root user in the user table. The host field indicates the host to log on to. The value can be an IP address or a host name,
(1) If you want to log on with a local IP address, you can change the Host value to your own Ip address.
2. implement remote connection (authorization)
Changing the value of the host field to % indicates that you can log on to the mysql server as a root user on any client machine. We recommend that you set the value to % during development.
Update user set host = '%' where user = 'root ';
Change the permission to all privileges.
Mysql> use mysql;
Database changed
Mysql> grant all privileges on *. * to root @ '%' identified by "root ";
Query OK, 0 rows affected (0.00 sec) www.2cto.com
Mysql> select host, user, password from user;
+ -------------- + ------ + --------------------------------------------- +
| Host | user | password |
+ -------------- + ------ + --------------------------------------------- +
| Localhost | root | * A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | * A731AEBFB621E354CD41BAF207D884A609E81F5E |
| % | Root | * A731AEBFB621E354CD41BAF207D884A609E81F5E |
+ -------------- + ------ + --------------------------------------------- +
3 rows in set (0.00 sec)
In this way, the machine can remotely access MySql on the machine with the username root Password root.
3. remote connection (Table change)
Use mysql;
Update user set host = '%' where user = 'root ';
In this way, you can access Mysql through the root user at the remote end.
Original blog: http://www.2cto.com/database/201205/130093.html.