How to Create a Username and Password in MySQL

A MySQL username and password are the credentials you use to log into your database server. Unlike the system username on your hosting account, a MySQL username is specific to the database itself — you can create multiple MySQL users with different permissions, and each one needs its own password. You create both through the MySQL command line or through your hosting control panel (usually cPanel or Plesk), depending on what access you have.

The simplest path for most people is the control panel, because it handles the technical syntax for you. If you have only command-line access, the process takes a few more steps but follows the same logic: you tell MySQL to create a new user, assign that user a password, and then decide what that user is allowed to do.

Key Takeaways

  • A MySQL username and password are separate from your hosting account login and control only database access, not server access.
  • If your hosting account includes cPanel or Plesk, use the MySQL user creation tool there instead of the command line — it requires no syntax knowledge.
  • After creating the username and password, you must also grant that user permission to access specific databases, or the credentials will not work.
  • Write down the username, password, and database name together in a safe place, because you will need all three to connect from your process.
  • A strong MySQL password should be at least 12 characters and include uppercase, lowercase, numbers, and symbols — the same rules as any other password.

Creating a MySQL User Through cPanel

Open cPanel and look for the MySQL Databases icon (sometimes labeled MySQL Database Wizard). Click it. You will see a section called Add New User with fields for username, password, and password confirmation.

Type your desired username into the first field. Most hosting providers prefix this with your cPanel username automatically — for example, if your cPanel login is johnsmith and you type wordpress, the full username becomes johnsmith_wordpress. This is normal and expected. Choose something short and descriptive, like the name of the process that will use it (wordpress, forum, shop).

In the password field, enter a strong password. Use at least 12 characters mixing uppercase letters, lowercase letters, numbers, and symbols. cPanel usually shows a password strength meter as you type. Aim for "Strong" or higher. Type the same password again in the confirmation field to make sure there are no typos.

Click Create User. cPanel will confirm that the user was created. You now have a MySQL username and password, but the user cannot access any databases yet — that is the next step.

Creating a MySQL User Through Plesk

Open Plesk and navigate to Databases in the left sidebar. Click Add Database or look for a Users tab depending on your Plesk version. If you see a Users tab, click it and then click Add User.

Enter your desired username. Like cPanel, Plesk usually prefixes this with your account name. Type a strong password (12 characters, mixed case, numbers, and symbols) and confirm it. Click OK or Add.

Plesk will show the new user in the list. Note the full username (including any prefix) and keep your password in a safe place. You will need both when you grant this user access to a database.

Creating a MySQL User From the Command Line

If you have SSH access but no control panel, you can create a MySQL user directly. Open your terminal and log into MySQL by typing mysql -u root -p, then press Enter. MySQL will ask for the root password. Type it (you will not see the characters as you type) and press Enter again.

You are now at the MySQL prompt, which looks like mysql>. Type the following command, replacing newuser with your desired username and password123 with a strong password:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password123';

Press Enter. MySQL will confirm with Query OK. The user now exists, but has no permissions. To grant this user access to a specific database, type:

GRANT ALL PRIVILEGES ON databasename.* TO 'newuser'@'localhost';

Replace databasename with the actual name of the database this user should access. Press Enter, then type FLUSH PRIVILEGES; and press Enter again. This tells MySQL to reload its permission tables. Type EXIT; to leave MySQL.

Granting Database Access to Your New User

Creating a username and password is only half the job. The user must also have permission to access at least one database, or login attempts will fail. In cPanel, after you create the user, you will see a section called Add User to Database. Select the username you just created from the first dropdown, select the database from the second dropdown, and click Add. A dialog will ask what permissions to grant — for most applications, select All Privileges.

In Plesk, go to the database itself, click Users, and add your new user there, selecting the permission level (usually Full for applications you control).

If you used the command line, you already granted access when you ran the GRANT command above. If you need to grant access to a different database later, log back into MySQL as root and run the same GRANT command with the new database name.

Where to Store Your MySQL Credentials

Write down three pieces of information together: the MySQL username, the password, and the database name. You will need all three when you configure an process (WordPress, a custom script, a web framework) to connect to the database. Do not store these in a text file on your desktop or in an email.

Use a password manager like Bitwarden, 1Password, or KeePass. These programs encrypt your credentials and let you retrieve them when you need them without typing them by hand. If you must write them on paper, keep the paper in a locked drawer. Never share these credentials with anyone except the person who will configure the process itself.

Testing Your New MySQL User

To confirm that your username and password work, log into MySQL using the new credentials. Open your terminal and type:

mysql -u newuser -p

Press Enter. MySQL will ask for the password. Type it and press Enter. If you see the mysql> prompt, the login worked. Type SHOW DATABASES; to see which databases this user can access. You should see the database you granted permission to. Type EXIT; to log out.

If you get an error like "Access denied for user", double-check that you typed the username and password correctly, and that you granted this user permission to at least one database. The most common mistake is forgetting the database permission step — the user exists but cannot access anything.

Frequently Asked Questions

Can I change a MySQL password after I create it?

Yes. In cPanel, go to MySQL Databases, find the user in the list, and click Change Password. In Plesk, click the user and select Change Password. From the command line, log in as root and type ALTER USER 'username'@'localhost' IDENTIFIED BY 'newpassword'; then FLUSH PRIVILEGES;.

What if I forget the MySQL password?

You can reset it through your control panel or command line using the steps above. You cannot recover the old password — you can only set a new one. If you have lost access to both the control panel and command line, contact your hosting provider's support team.

Can one MySQL user access multiple databases?

Yes. In cPanel or Plesk, add the same user to each database you want them to access. From the command line, run the GRANT command once for each database. The user will then be able to switch between them after login.

Is localhost the only option for the user host?

For most setups, yes — your process and database are on the same server, so localhost is correct. If your database is on a different server, you would use that server's IP address instead of localhost. Your hosting provider can tell you the correct host if you need it.

Do I need a different MySQL user for each process?

It is not required, but it is a good practice. If one process is compromised, the attacker gains access only to that process's database, not all of them. Create a separate user for WordPress, another for your forum, another for your custom app — each with its own password and access to only its own database.