Questions And Answers

More Tutorials

MYSQL Create New User

Create a MySQL User

For creating new user, We need to follow simple steps as below :

Step 1:

Login to MySQL as root

$ mysql -u root -p

Step 2 :

We will see mysql command prompt

mysql> CREATE USER 'my_new_user'@'localhost' IDENTIFIED BY 'test_password';

Here, We have successfully created new user, But this user won't have any permissions, So to assign permissions
to user use following command :

mysql> GRANT ALL PRIVILEGES ON my_db.* TO 'my_new_user'@'localhost' identified by 'my_password';

Specify the password

The basic usage is:

mysql> CREATE USER 'my_new_user'@'localhost' IDENTIFIED BY 'test_password';

However for situations where is not advisable to hard-code the password in cleartext it is also possible to specify directly, using the directive PASSWORD, the hashed value as returned by the PASSWORD() function:

mysql> select PASSWORD('test_password'); -- returns *4414E26EDED6D661B5386813EBBA95065DBC4728
mysql> CREATE USER 'my_new_user'@'localhost' IDENTIFIED BY PASSWORD

Create new user and grant all priviliges to schema

grant all privileges on schema_name.* to 'new_user_name'@'%' identified by 'newpassword';


This can be used to create new root user

Renaming user

rename user 'user'@'%' to 'new_name`@'%';

If you create a user by mistake, you can change his name.


In this page (written and validated by ) you learned about MYSQL Create New User . What's Next? If you are interested in completing MYSQL tutorial, your next topic will be learning about: MYSQL Security via GRANTs.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.