LochStudios  /  Help Centre  /  cPanel  /  Create a MySQL Database and User

Create a MySQL Database and User

Add a MariaDB database and user on your shared hosting, grant privileges, and copy the full prefixed names your application needs.

Updated

Every Beginner and Standard hosting plan includes unlimited MariaDB databases. cPanel still labels the tools MySQL. You create the database, create a user, then grant that user access. Sites that run on this account connect with host localhost.

If you are installing WordPress, use WordPress Toolkit or Installatron in cPanel first. Those installers create the database and user for you. See Install WordPress. Use the steps below when you need a database for a custom app, or when an installer asked you to create one yourself.

Open cPanel from the portal. Do not guess a hostname.

Open cPanel

  1. Sign in at the portal.
  2. Open the hosting service for the site.
  3. Click Log in to cPanel.

You do not need a server hostname to get in.

Create the database

  1. In the Databases section, open MySQL Databases.
  2. Under Create New Database, type a short name (letters, numbers, and underscores only).
  3. Click Create Database.
  4. Copy the full database name shown in the list. cPanel prefixes it with your account username. If you type shop, the name you use in the app is username_shop.

MySQL Database Wizard in the same section walks these three jobs (database, user, privileges) on one path. Use it if you prefer a single flow. The names and prefixes are the same.

Create the database user

  1. Still on MySQL Databases, scroll to MySQL Users / Add New User.
  2. Enter a username (letters, numbers, and underscores only).
  3. Set a strong password, or click Generate and copy the result somewhere safe. This is the database user password. It is not your portal password, and it is not the cPanel owner password unless you set them the same.
  4. Click Create User.
  5. Copy the full username from the list. It is prefixed the same way as the database (username_shopuser).

Assign the user to the database

A new user cannot read or write anything until you attach it.

  1. Scroll to Add User To Database.
  2. Choose the user you just created.
  3. Choose the database.
  4. Click Add.
  5. Tick ALL PRIVILEGES unless the application documents a shorter list. Most apps need SELECT, INSERT, UPDATE, and DELETE at minimum.
  6. Click Make Changes.

You can attach the same user to more than one database, or give a second user a narrower set of privileges.

Connection details for the app

Put these values in the application's config (for WordPress that is wp-config.php). Use the full prefixed names from the lists, not the short names you typed.

SettingValue
Hostlocalhost
Port3306 (usually you can leave this blank)
DatabaseFull name, including the account prefix
UsernameFull username, including the account prefix
PasswordThe password you set for that database user

localhost is correct when the site or script runs on this hosting account. Do not put your website domain or a guessed server name in the host field. That can send the connection to the wrong place.

Need a tool on your computer, or an app on another server, to reach this database? That is remote access, and localhost will not work. See Allow Remote MySQL Access.

If WordPress on this account cannot connect after you saved the file, see Fix "Error Establishing a Database Connection" in WordPress.

After it is created

  • Browse and edit: open phpMyAdmin from the Databases section, or use the phpMyAdmin link next to the database on MySQL Databases.
  • Change the user password: on MySQL Databases, find the user and set a new password. Then update every application that uses that user.
  • Remove a user or database: use the delete controls on the same page. Deleting a database removes its tables and data. Export a copy from phpMyAdmin first if you might need it.
  • Copies we keep: hourly backups include the databases on this account. To put one back from those copies, open a support ticket. You can also export from phpMyAdmin or use Download and Restore a Backup.

If the application still cannot connect after you have checked the full names, the password, and localhost, open a support ticket and we will look at the account with you. Include the full database name and username (not the password).

Related


Was this article helpful?

← Back to cPanel