
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Create a new user with password in MySQL 8?
You need to use CREATE command to create a new user with password in MySQL 8. Let us check the version
mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.14 sec)
The syntax is as follows to create a new user with password
CREATE USER 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';
The following is the syntax to grant all privileges to the created user
GRANT ALL ON *.* TO 'yourUserName'@'localhost';
Now flush the privileges using flush command
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 privileges to the newly created user
mysql> GRANT ALL ON *.* TO 'James'@'localhost'; Query OK, 0 rows affected (0.18 sec)
Let us check the user has been created or not
mysql> select user from MySQL.user;
The following is the output displaying the new user we created above
+------------------+ | 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)
Look at the sample output, the user James has been created successfully. Now flush the privileges using a flush command. The query is as follows
mysql> flush privileges; Query OK, 0 rows affected (0.04 sec)
- Related Articles
- Set special characters for password while creating a new MySQL user?
- MySQL CREATE USER with a variable?
- Can we convert MD5 to SHA256 in a MySQL table with user password column?
- Create a new database with MySQL Workbench?
- Create a new user and set role in MongoDB
- How can we change MySQL user password by using the SET PASSWORD statement?
- Create a new table in MySQL with specific options with DEFAULT?
- How can we change MySQL user password by using the ALTER USER statement?
- How can a user start new MySQL transaction?
- How to create MySQL user with limited privileges?
- How to create a new local user in windows using PowerShell?
- How can we change MySQL user password by using UPDATE statement?
- Authorize a new user in SAP
- MySQL new user access denied even after giving privileges?
- How to create a new table from merging two tables with MySQL union?

Advertisements