MySQL remote access, that is, through IP access to the MySQL service, MySQL requirements for security is very strict and requires authorization.
1. Local Access
SQL code
- GRANT All privileges on * * to [e- Mail protected] identified by ' admin ' with GRANT OP tion;
- FLUSH privileges;
The above command means for admin user authorization, to access the database in localhost , password is admin, this is our recommended way of access, do not directly expose IP, improve the security of the database server.
2. Remote Access
If the database server and the application server physically split, that is not the same server, we need to access IP, this IP is the database server host IP.
SQL code
- GRANT All privileges on * * to [e- Mail protected] identified by ' admin ' with GRANT option;
- FLUSH privileges;
Of course, this grants Admin user with grant OPTION permission, less than secure! If a user modifies the database table structure from remote login and so on, it is very risky!
It is generally not recommended to grant rights to other users, namely:
SQL code
- GRANT all privileges on * * to [email protected] identified by ' admin ';
- FLUSH privileges;
3. Any Access
If you do not restrict IP access, authorizing a user to access the service with any IP, you can write:
SQL code
- GRANT all privileges on * * to [email protected]'% ' identified by ' admin ';
- FLUSH privileges;
Note Single Quotes!
3. Cancellation of Authorization
Of course, with authorization, there must be a cancellation authorization:
SQL code
- revoke all on *.* from [email protected];
- flush privileges;