Create a MySQL database user through the following steps: 1. Use the CREATE USER statement to create a new user; 2. Grant permissions (optional); 3. Refresh permissions so that the permissions take effect immediately.
Create MySQL database user
Question: How to create a MySQL database user?
Answer:
Create a MySQL database user in the following steps:
1. Use the CREATE USER statement
CREATE USER
statement is used to create a new user. The syntax is as follows:
<code class="sql">CREATE USER [IF NOT EXISTS] username IDENTIFIED BY 'password';</code>
username
: The username of the new user. password
: The password of the new user. For example, create a user named newuser
:
<code class="sql">CREATE USER newuser IDENTIFIED BY 'password123';</code>
2. Grant permissions (optional)
New users have no permissions by default. You can grant permissions using the GRANT
statement, for example:
<code class="sql">GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO newuser;</code>
database_name
: The name of the database to which permissions are granted. newuser
: The user to whom permissions are to be granted. 3. Refresh permissions
In order for the permissions to take effect immediately, you need to refresh the permissions:
<code class="sql">FLUSH PRIVILEGES;</code>
Other notes:
The above is the detailed content of How to create a database user in mysql. For more information, please follow other related articles on the PHP Chinese website!