
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create MySQL User If It Does Not Exist
You can create user if it does not exist with the help of “create user” command. The command will work on MySQL version 5.7.6 and above. The syntax is as follows −
mysql> CREATE USER IF NOT EXISTS 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';
Apply the above syntax to create a user if it does not exist. The query is as follows −
mysql> CREATE USER IF NOT EXISTS 'Smith'@'localhost' IDENTIFIED BY 'Smith123456'; Query OK, 0 rows affected (0.29 sec)
To check the new user is created or not, use the below query −
mysql> SELECT User FROM mysql.user;
The following is the output −
+------------------+ | User | +------------------+ | John | | Mac | | Manish | | mysql.infoschema | | mysql.session | | mysql.sys | | root | | Smith | | am | +------------------+ 9 rows in set (0.00 sec)
Look at the above output, the use “Smith” created successfully.
Advertisements