Home >Database >Mysql Tutorial >MySQL creates user accounts and deletes user accounts
mysqlCreate user account
To create a new user account, use the CREATE USER statement, as follows:
Enter:
create user ben identified by 'p@$$w0rd';
Analysis: CREATE USER creates a new user account. A password is not necessarily required when creating a user account, but this example gives one using IDENTIFIED BY 'p@$$wOrd'. If you list the user accounts again, you will see the new accounts in the output.
Specify the hashed password IDENTIFIED BY The specified password is plain text, and MySQL will encrypt it before saving it to the user table. To specify a password as a hash value, use IDENTIFIED BY PASSWORD.
User accounts can also be created using the GRANT or INSERT GRANT statements (described later), but generally CREATE USER is the clearest and simplest statement. In addition, you can also add users by directly inserting rows into the user table, but for security reasons, this is generally not recommended. The tables (and table schemas, etc.) used by MySQL to store user account information are extremely important, and any damage to them may seriously harm the MySQL server. Therefore, it is better to use tags and functions to process these tables than to process them directly.
To rename a user account, use the RENAME USER statement, as follows:
Input:
rename user ben to bforta;
Before MySQL 5, only MySQL 5 or later versions supported RENAME USER. . To rename a user in previous MySQL, use UPDATE to directly update the user table.
mysql delete user accountIn order to delete a user account (and related permissions), use the DROP USER statement, as shown below:
Enter :
drop user bforta;
Before MySQL 5 Since MySQL 5, DROP USER deletes the user account and all related account permissions. Before MySQL 5, DROP USER could only be used to delete user accounts, but not related permissions. Therefore, if you use an older version of MySQL, you need to first use REVOKE to delete the permissions related to the account, and then use DROP USER to delete the account.
【Related recommendations】
Mysql free video tutorialCommand line example operations for mysql user management and password changeSeveral points to note about mysql access controlMySQL character set and collation order tutorialIntroduction to MySQL character set and collation orderThe above is the detailed content of MySQL creates user accounts and deletes user accounts. For more information, please follow other related articles on the PHP Chinese website!