By default, MySQL cannot be accessed through a remote machine. The following configuration allows you to enable remote access.
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 ).
- # You must add an account like this to log on remotely. The root account cannot be remotely logged on. You can only log on locally.
Mysql> use MySQL; mysql> grant all on *. * To admin @ '%' identified by 'admin' with grant option; # allow any IP address (% above) use the admin account and password (Admin) to access this MySQL Server # You must add an account similar to this to remotely log on. The root account cannot be remotely logged on. You can only log on locally.
So how to remotely access it?
On another MYSQL client (PC with MySQL package installed, either Windows or Linux)
Run the following command:
- Mysql-h172.21.5.29-uadmin-padmin.
- // 172.21.5.29 is the IP address of MySQL server, and Admin admin is the remote access account just set on 172.21.5.29.
Mysql-h172.21.5.29-uadmin-padmin. // 172.21.5.29 is the IP address of the MySQL server, and Admin admin is the remote access account set on 172.21.5.29.
Reference 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 ).
# You must add an account like this to log on remotely. The root account cannot be remotely logged on. You can only log on locally.
I found a problem. If you have finished executing the above command, you will be running localhost locally. Execute:
- Mysql-hlocalhost-uadmin-padmin
mysql -hlocalhost -uadmin -padmin
The result is failed.
The above % does not include localhost.
So you must add such a command.
Mysql> grant all on *. * to admin @ 'localhost' identified by 'admin' with grant option;
By default, MySQL cannot be accessed through a remote machine. The following configuration allows you to enable remote access.
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 ).
- # You must add an account like this to log on remotely. The root account cannot be remotely logged on. You can only log on locally.
Mysql> use MySQL; mysql> grant all on *. * To admin @ '%' identified by 'admin' with grant option; # allow any IP address (% above) use the admin account and password (Admin) to access this MySQL Server # You must add an account similar to this to remotely log on. The root account cannot be remotely logged on. You can only log on locally.
So how to remotely access it?
On another MYSQL client (PC with MySQL package installed, either Windows or Linux)
Run the following command:
- Mysql-h172.21.5.29-uadmin-padmin.
- // 172.21.5.29 is the IP address of MySQL server, and Admin admin is the remote access account just set on 172.21.5.29.
Mysql-h172.21.5.29-uadmin-padmin. // 172.21.5.29 is the IP address of the MySQL server, and Admin admin is the remote access account set on 172.21.5.29.
Reference 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 ).
# You must add an account like this to log on remotely. The root account cannot be remotely logged on. You can only log on locally.
I found a problem. If you have finished executing the above command, you will be running localhost locally. Execute:
- Mysql-hlocalhost-uadmin-padmin
mysql -hlocalhost -uadmin -padmin
The result is failed.
The above % does not include localhost.
So you must add such a command.
Mysql> grant all on *. * to admin @ 'localhost' identified by 'admin' with grant option;