Home >Database >Mysql Tutorial >Create a new user with password in MySQL 8?

Create a new user with password in MySQL 8?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-08-30 23:09:021439browse

在 MySQL 8 中创建一个带有密码的新用户?

In MySQL 8, you need to use the CREATE command to create a new user with a password. Let’s check the version

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.12    |
+-----------+
1 row in set (0.14 sec)

The syntax to create a new user with password is as follows

CREATE USER 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';

The following is the syntax to grant all permissions to the created user

GRANT ALL ON *.* TO 'yourUserName'@'localhost';

Now use flush Command refresh permissions

flush privileges;

Let us create a new user with the help of the above syntax. The query is as follows

mysql> use MySQL;
Database changed
mysql> CREATE USER 'James'@'localhost' IDENTIFIED BY 'James123456';
Query OK, 0 rows affected (0.21 sec)

The following is the query to grant all permissions to the newly created user

mysql> GRANT ALL ON *.* TO 'James'@'localhost';
Query OK, 0 rows affected (0.18 sec)

Let us check if the user has been created

mysql> select user from MySQL.user;

The following is the query to show the new user we created above User's output

+------------------+
| user             |
+------------------+
| Bob              |
| Manish           |
| User2            |
| mysql.infoschema |
| mysql.session    |
| mysql.sys        |
| root             |
| @UserName@       |
| Adam Smith       |
| James            |
| John             |
| John Doe         |
| User1            |
| am               |
| hbstudent        |
| mysql.infoschema |
| mysql.session    |
+------------------+
17 rows in set (0.00 sec)

View the sample output, user James has been successfully created. Now refresh the permissions using refresh command. The query is as follows

mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)

The above is the detailed content of Create a new user with password in MySQL 8?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete