When we create a website, we generally need to use a database. For security reasons, non-root users are recommended. Common commands are as follows:
1. Create a new user
Log in to MySQL
@>mysql-u root-p
@> Password
Create user
mysql> INSERT INTO Mysql.user (Host,user,password) VALUES (' localhost ', ' Allen ', Password (' Allen '));
Refresh System Permissions Table
Mysql>flush privileges;
This creates a user named Allen with the password: Allen.
Log in after exiting
mysql>exit;
@>mysql-u allen-p
@> Enter password
Mysql> Login Successful
2. Authorizing the user
Log in to MySQL (with root privileges). I am logged in as root.
@>mysql-u root-p
@> Password
First create a database for the user (ALLENDB)
Mysql>create database allendb;
Empower Allen users to have all the permissions of the Allen database
@>grant all on allendb.* to Allen@localhost identified by ' Allen ';
Refresh System Permissions Table
Mysql>flush privileges;
Mysql> Other operations
If you want to specify partial permissions to a user, you can write:
Mysql>grant select,update on jeecndb.* to Allen@localhost identified by ' Allen ';
Refreshes the System permissions table.
Mysql>flush privileges;
Mysql> grant permissions 1, permissions 2,... Permission n on the database name. Table name to User name @ user address identified by ' connection password ';
Permissions 1, Permissions 2,... Permission n represents 14 permissions, such as Select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file.
When permissions 1, permissions 2,... Permission n is replaced by all privileges or all to give the user full permission.
The second MySQL common Operation Record (reprint)