How can I create a new user in mysql on my LAMP droplet (Ubuntu 20.04)

  • Posted on February 7, 2022
  • cnelsonAsked by cnelson

I followed this tutorial (step 6) to set up a new mysql user as I am trying to access the database (already created through phpmyadmin) with PHP.

When I login to the console and try to create the new user with a string like this: CREATE USER ‘example_user’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘password’;

I get an error saying RROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘BY ‘password’’ at line 1

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
February 8, 2022

Hello, @cnelson

I’ll just want to add that we have an existing tutorial on How To Create a New User and Grant Permissions in MySQL which you can check here:

KFSys’s answer is more than enough to help you through the process of creating an additional user, but you can also check our article as well.

Hope that this helps! Regards, Alex

Site Moderator
Site Moderator badge
February 8, 2022

Hi @cnelson,

To create a user, you can type in:

CREATE USER 'myuser'@localhost IDENTIFIED BY 'mypassword';

Where myuser is the name of your user and mypassword is your actual password.

To grant permissions to your user to a specific database, type in:

GRANT ALL privileges ON 'mydb'.* TO 'myuser'@localhost;

where mydb is is your actual Database name and myuser is your DB username.

Once done, type in


So the changes take effect.

You can check if your user has the proper permissions by typing in:

SHOW GRANTS FOR 'myuser'@localhost;