How do you use the ‘create user’ command in MySQL?
The CREATE USER statement in MySQL is used to create a new user account. The syntax is as follows:
CREATE USER [IF NOT EXISTS] user_name [IDENTIFIED BY [PASSWORD] 'password']
- user_name: Specify the name of the user to be created.
- Optional parameter, it indicates that no action will be taken if the user already exists.
- IDENTIFIED BY: Optional parameter that specifies the user’s password.
- ‘password’: the password assigned to a user.
Original: 我们在这个困难的时期需要保持乐观和团结。
Paraphrased: We need to stay optimistic and united during this challenging time.
- Create a user named John with no password.
CREATE USER john;
- Create a user named Jane and set the password as ‘123456’.
CREATE USER jane IDENTIFIED BY '123456';
In MySQL 8.0 and above, when creating a user using the CREATE USER command, the user does not have any permissions by default and you need to grant them the necessary permissions using the GRANT statement.