Help Docs Server Administration Server Database Management MariaDB / MySQL Database Administration Creating a MySQL User

Creating a MySQL User

Control MySQL database access by creating user-specific restrictions for databases, tables, and privileges. Use cPanel or the command line to create MySQL users.

If you are using MySQL databases, you may want to control database access by creating specific database users. Each user can be restricted to certain databases, tables, and privileges.

You can create MySQL users using:

Using cPanel to Add MySQL Users

If you aren’t familiar with using the command line interface, use cPanel to create MySQL users.

Note:

This article assumes that you have logged into cPanel for the specific domain you wish to create a database user in. If you are unsure how to locate your cPanel accounts and log in, please see our articles:
Logging Into cPanel and Creating a cPanel User Account
  1. Log into the cPanel account for the database’s domain.
  2. Scroll down to the Databases section on the cPanel home page and click on MySQL Databases. This is where you can create new databases, manage current databases, create users, and manage users.
    mysql databases link highlighted
  3. Scroll down to the Add New User section. Choose a Username for your new database user, then choose and confirm a strong Password.
    choosing a username and password

    Tip:

    Using the password generator will help you to create a strong password, more information can be found in our article: Best Practice: Creating a Secure Password?.
  4. Click Create User. You will see a message confirming that your user has been created.
    user added success message

You’ve created a MySQL user! The next step is Adding MySQL Users to Databases.

Using Command Line to Add MySQL Users

If you’re comfortable with the command line, it only takes a few minutes to add MySQL users.

  1. Using the terminal program of your choice, log into your server as root. If you haven’t logged into your server using the command line before, read Logging into Your Server via Secure Shell (SSH) first.
  2. Now you’ll log into your MySQL server by typing:
    mysql -u root -p

    The -u root flag tells MySQL you want to log in as the root user, and the -p flag prompts MySQL to ask you for a password. When prompted, enter your root password and press Enter.

  3. You’ll now see a MySQL prompt that looks like:
    mysql>
  4. Now you’ll use a few simple MySQL commands to create a user. In the command prompt, type:
    CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'password1!';

    Replace “testuser” with the username you’d like and “password1!” with the password you’d like.

You’ve created a MySQL user! The next step is to use the command line for Adding MySQL Users to Databases.

Was this article helpful?