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

Create a new user with password in MySQL 8?

WBOY
Release: 2023-08-30 23:09:02
forward
1395 people have browsed it

在 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)
Copy after login

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

CREATE USER 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';
Copy after login

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

GRANT ALL ON *.* TO 'yourUserName'@'localhost';
Copy after login

Now use flush Command refresh permissions

flush privileges;
Copy after login

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)
Copy after login

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)
Copy after login

Let us check if the user has been created

mysql> select user from MySQL.user;
Copy after login

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template