How to Add a User to a MariaDB/MySQL Database

PHP/MariaDB/MySQL | Updated March 2026

Every application that uses a database (WordPress, Joomla, custom PHP apps) needs a database user with the right permissions. This guide covers how to create databases, create users, and assign users to databases in cPanel. It also covers common issues like forgotten passwords, permission errors, and the cPanel username prefix system.

01. Create a Database

  1. Log into cPanel - go to your hosting control panel
  2. Click "MySQL Databases" - in the Databases section
  3. Enter a name - under "Create New Database," type a name (e.g., wpdb). cPanel will add your username prefix automatically
  4. Click "Create Database"

The database is now created but empty and has no users assigned to it. A database without a user is inaccessible to applications.

02. Create a Database User

  1. On the same MySQL Databases page - scroll down to "MySQL Users"
  2. Enter a username - (e.g., dbuser). Again, cPanel adds the prefix
  3. Enter a password - use the Password Generator for a strong random password. Copy it somewhere safe; you'll need it for your application's config file
  4. Click "Create User"
Warning

The user is created but has no access to any database yet. You must complete Step 3 (Assign User to Database) or your application will show "Access denied" errors.

03. Assign User to Database

  1. Scroll to "Add User to Database" - still on the MySQL Databases page
  2. Select the user - from the User dropdown
  3. Select the database - from the Database dropdown
  4. Click "Add"
  5. Set privileges - check "ALL PRIVILEGES" for most applications, or select specific privileges if you need restricted access (see Section 4)
  6. Click "Make Changes"

The user now has access to the database. Your application's config file needs three values:

# WordPress example (wp-config.php):
define('DB_NAME', 'myaccount_wpdb');
define('DB_USER', 'myaccount_dbuser');
define('DB_PASSWORD', 'the_password_you_set');
define('DB_HOST', 'localhost');

04. Understanding Privileges

For most applications (WordPress, Joomla, Drupal, custom apps), grant ALL PRIVILEGES. This lets the application create tables, insert/update/delete data, and manage the schema as needed.

If you need to restrict a user (e.g., for a read-only reporting connection), here's what the key privileges do:

  • SELECT - read data
  • INSERT - add new rows
  • UPDATE - modify existing rows
  • DELETE - remove rows
  • CREATE - create new tables
  • DROP - delete tables (careful with this one)
  • ALTER - modify table structure (columns, indexes)
  • INDEX - create and delete indexes
Tip

WordPress needs at minimum: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, and DROP. But it's simpler and safer (for updates and migrations) to just grant ALL PRIVILEGES unless you have a specific security reason not to.

05. Change a Database User Password

  1. Go to MySQL Databases in cPanel
  2. Scroll to "Current Users" - find the user you want to change
  3. Click "Change Password"
  4. Enter the new password and click "Change Password"
  5. Update your application config - change the password in wp-config.php (WordPress), configuration.php (Joomla), or wherever your application stores database credentials
Warning

Changing the database password in cPanel does NOT update your application's config file. If you change the password without updating the config, your site will show "Error establishing a database connection" until you update the password in the config file to match.

06. Using phpMyAdmin

phpMyAdmin is a web-based tool for directly managing database contents. Access it from cPanel > Databases > phpMyAdmin.

Common Tasks

  • Browse data - click a database, then a table, to see its contents
  • Run SQL queries - click the SQL tab to run custom queries
  • Import data - click Import to upload a .sql file (useful for restoring backups or migrating)
  • Export data - click Export to download a .sql dump (useful for backups)
  • Search and replace - click the Search tab on a table to find specific values. Useful for finding hardcoded URLs after a domain or SSL change
  • Optimize tables - select all tables, choose "Optimize table" from the dropdown. Reclaims disk space and can improve performance

For connection details and remote access, see our MySQL Port and Connection Guide.

07. Troubleshooting

"Error Establishing a Database Connection"

The most common database error. Check these in order:

  1. Database name - must include the cPanel prefix (e.g., myaccount_wpdb not wpdb)
  2. Username - must also include the prefix
  3. Password - must match exactly what's set in cPanel MySQL Databases
  4. User assigned to database - the user must be added to the database (Step 3 above)
  5. DB_HOST - should be localhost for apps on the same server

"Access Denied for User"

The user exists but doesn't have permission to access the specific database. Go to MySQL Databases, scroll to "Add User to Database," and add the user to the correct database with ALL PRIVILEGES.

"Unknown Database"

The database name in your config doesn't match any database in your account. Check the exact name (with prefix) in cPanel > MySQL Databases. Database names are case-sensitive on Linux.

"Too Many Connections"

Your application has too many simultaneous database connections open. This is usually caused by missing persistent connection settings or a traffic spike. If it happens consistently, you may need to optimize your application's database connection handling or consider a VPS or dedicated server with higher connection limits.

Need Help With Databases?

If you're having trouble setting up or connecting to a database, open a support ticket with the exact error message and which application you're configuring.

Open a Support Ticket

Quick Recap: MySQL Database Setup

If you only do 5 things from this guide, do these:

  1. Create the database - cPanel > MySQL Databases > Create New Database
  2. Create a user - with a strong generated password
  3. Add the user to the database - with ALL PRIVILEGES
  4. Use the prefixed names - youraccount_dbname in your config file
  5. Set DB_HOST to localhost - for applications on the same server

Last updated March 2026 · Browse all Database articles

  • 875 Users Found This Useful

Was this answer helpful?

Related Articles

PHP information

To view your current version of PHP you will create a php file, for example info.php, and place...

What Port is MariaDB/MySQL On?

PHP/MariaDB/MySQL | Updated March 2026 MariaDB/MySQL runs on port 3306 by default on all...

Running a PHP file with a cron job

To run a PHP file from cron, use the "cron jobs" section of your control panel. Use the following...

I am having problems with a script I wrote

PHP suexec is running on all of our shared servers. If you are running code that is insecure or...

Clean - Shrink ibdata1

To shrink ibdata1 once and for all you must do the following:MySQLDump all databases into a SQL...



Save 30% on web hosting - Use coupon code Hosting30