1. Create a new user
- Login to MYSQL:
@>mysql -u root -p
@> password
- Create user:
mysql> insert into mysql.user(Host,User,Password) values("localhost","healthyuser",password("admin"));
This creates a user named: healthyuser with password: admin .
Note : "localhost" here means that the user can only log in locally and cannot log in remotely on another machine. If you want to log in remotely, change "localhost" to "%", which means you can log in from any computer. You can also specify a machine that can log in remotely.
- Then log in:
mysql>exit;
@>mysql -u test -p
@> enter password
mysql> login successful
2. Authorize the user
Authorization format: grant permission on database.* to username@login host identified by "password";
- Log in to MYSQL (with ROOT privileges), here log in as ROOT:
@>mysql -u root -p
@> password
- First create a database for the user ( healthy ):
mysql>create database healthy;
- Authorize the healthyuser user to have all permissions on the healthy database (all permissions on a database):
mysql>grant all privileges on healthy.* to healthyuser@localhost identified by 'admin';
mysql>flush privileges;//Refresh the system privilege table
Format: grant permission on database.* to username@login host identified by "password";
- If you want to assign partial permissions to a user, you can write:
mysql>grant select,update on healthy.* to healthyuser@localhost identified by 'admin';
mysql>flush privileges; //Refresh the system privilege table
- Authorize the healthyuser user to have certain permissions on all databases :
mysql>grant select,delete,update,create,drop on *.* to healthyuser@"%" identified by "admin";