1.Create User
Syntax:CREATE USER 'username ' @ ' host' identified by ' password ';
eg
CREATE USER ' pig ' @ ' 192.168.1.101 ' idendified by ' 123456 '; this restricts the IP of the accessible host to 192.168.1.101
CREATE USER ' pig ' @ '% ' identified by ' 123456 '; indicates that any host can access
Create user JSS; //You can create a connection from any machine that has a MySQL client installed and can access the target server without a password
2.Grant Statements
Syntax:grant permissions 1, permissions 2,... Permission n on the database name. Table name to User name @ user address identified by ' connection password ';
eg
Grant Select,insert,update,delete,create,drop on Mydb.user to [e-mail protected] identified by ' 123 ';// The user admin from 192.168.1.101 is assigned the ability to perform operations such as Select,insert,update,delete,create,drop on the MyDB user table of the database, and the password is set to 123.
grant all privileges on mydb.* to [email protected] identified by ' 123 ' ;/ /Assign the user admin from 192.168.1.101 to all operations on the database mydb all tables, and set the password to 123
Grant all privileges on * * to [e-mail protected] identified by ' 123 ';//Assign user admin from 192.168.1.101 ' to the all tables in all databases have permission to operate and set the password to 123
3. Inserting data directly into the table
Insert into User (Host,user,password) values ('% ', ' admin ', password (' 123 '));
Flush privileges; //Refresh System Permissions Table
4. Change the password
4.1. Using Mysqladmin
syntax: mysqladmin-u user name-p old password password new password
eg
Mysqladmin-u root-p 123 Password 456;
4.2. Directly modify user's password
syntax: Update mysql.user set Password=password (' New password ') where user= "Phplamp" and host= "localhost";
eg
Update user set Password=password (' 54netseek ') where user= ' root ';
Flush privileges; //Refresh the System permissions table
4.3. Using the Set Password statement to modify the password
syntax: SET PASSWORD for ' username ' @ ' host ' = PASSWORD (' NewPassword ');
remove the For ' username ' @ ' host ' if it is the current user
5. Cancellation of the account and its authorization
Drop user User;
drop user [email protected] '% '
drop user [email protected]
6. Remove Permissions
syntax: REVOKE privilege on databasename.tablename from ' username ' @ ' host ';
eg
REVOKE SELECT on Test.user from ' pig ' @ '% ';
Revoke all on user.* from ' admin ' @ '% ';
SHOW GRANTS for ' pig ' @ '% '; //view authorizations
7. Delete Account
syntax: Delete from user where user = "user_name" and host = "host_name";
eg
Delete from user where user= ' admin ' and host= ' localhost ';
The creation of the MySQL user