The first phase of basic knowledge about MySQL: How to remotely access the MySQL database and how to set permissions. This section discusses how to access a single database, all databases, specify user access, set access passwords, and specify access hosts.
1. Set the permissions to access a single database
Copy codeThe Code is as follows:
Mysql> grant all privileges on test. * to 'root' @ '% ';
Note: The user name is set to root, and the password is blank. You can access the database test.
2. Set all Database Access Permissions
Copy codeThe Code is as follows:
Mysql> grant all privileges on *. * to 'root' @ '% ';
Note: Set the username to root and the password to null to allow access to all databases *
3. Set the access permission for the specified user name
Copy codeThe Code is as follows:
Mysql> grant all privileges on *. * to 'liuhui' @ '% ';
Note: Set the specified user name to liuhui and the password to be blank to allow access to all databases *
4. Set password access permissions
Copy codeThe Code is as follows:
Mysql> grant all privileges on *. * to 'liuhui' @ '%' identified by 'liuhui ';
Note: Set the specified user name to liuhui and the password to liuhui to access all databases *
5. Set the specified accessible host permissions.
Copy codeThe Code is as follows:
Mysql> grant all privileges on *. * to 'liuhui' @ '10. 2.1.11 ';
Note: Set the specified user name to liuhui to access all databases. * only the machine 10.2.1.11 has the permission to access the database.
You can also set to access a data table in a database. Follow the MySQL basics series.