
- 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
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 Articles
- Create view in MySQL only if it does not already exist?
- How to check if a table exists in MySQL and create 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 can I create a directory if it does not exist using Python?
- Create a table if it does not already exist and insert a record in the same query with MySQL
- Insert records in MongoDB collection if it does not exist?
- Does NOT EQUAL exist in MySQL?
- PHP and MYSQL database connection and table creation only once if it does not already exist?
- Select from table where value does not exist with MySQL?
- MongoDB query to determine if a specific value does not exist?
- Upsert in MongoDB while using custom _id values to insert a document if it does not exist?
- 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)?
- Java Selenium Chromedriver.exe Does not Exist IllegalStateException

Advertisements