

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
MySQL create 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.
- Related Questions & Answers
- Create view in MySQL only if it does not already exist?
- How can I create a python directory if it does not exist?
- How to create a folder if it does not exist in C#?
- How to check if a table exists in MySQL and create if it does not already exist?
- How can I create a directory if it does not exist using Python?
- Insert records in MongoDB collection if it does not exist?
- Does NOT EQUAL exist in MySQL?
- Create a table if it does not already exist and insert a record in the same query with MySQL
- PHP and MYSQL database connection and table creation only once if it does not already exist?
- MongoDB query to determine if a specific value does not exist?
- Select from table where value does not exist with MySQL?
- Upsert in MongoDB while using custom _id values to insert a document if it does not exist?
- Java Selenium Chromedriver.exe Does not Exist IllegalStateException
- Add object to array in JavaScript if name does not already exist?
- Insert array where element does not exist else update it (with multiple conditions)?
Advertisements