Contents
A MySQL setup on cPanel hosting always has three parts: the database, a database user, and the link between them that grants privileges. Most “access denied” errors come from skipping the third part. MariaDB, the MySQL-compatible server many hosts run, works exactly the same way, so everything below applies to both.
Before you start
- Access to your control panel: cPanel, or the Araby Panel if you host with ArabyHost.
- A short name for the database in lowercase letters, digits and
_, such asshoporblog. - A strong password. Generate one with the password generator and store it in a password manager.
- Optional: SSH access, if you prefer the terminal (method 3).
Method 1: cPanel → Manage My Databases
1. Create the database
In cPanel, open Databases → Manage My Databases (older versions call it MySQL® Databases). Under Create New Database, type the name and click Create Database. cPanel adds your account name as a prefix, so shop becomes something like myuser_shop.
2. Create the user
Scroll to MySQL Users → Add New User. Enter a username (it gets the same prefix), type the password twice and click Create User. A database user is separate from your cPanel login; never reuse that password.
3. Add the user to the database
Under Add User To Database, pick the user and the database, then click Add. On the Manage User Privileges screen, tick ALL PRIVILEGES and click Make Changes. For an app that only reads data, SELECT alone is enough.
Prefer a guided flow? Databases → Database Wizard walks through the same three steps on separate screens.
Method 2: the Araby Panel
On ArabyHost, open your service, then the Databases tab, type the name and click Create database. The panel creates the database and a matching user with full access, then shows the host, database, username and password once. Copy them before you click I saved it. The short version is in Create a database and connect your site.
Method 3: over SSH with uapi
On plans with SSH, cPanel’s uapi command does the same job. Read the password into a variable so it doesn’t end up in your shell history:
read -rs DBPASS # type the password, then press Enter
uapi Mysql create_database name=myuser_shop
uapi Mysql create_user name=myuser_shopapp password="$DBPASS"
uapi Mysql set_privileges_on_database user=myuser_shopapp database=myuser_shop privileges='ALL PRIVILEGES'
unset DBPASS
Each command prints status: 1 on success. status: 0 comes with an errors: line that explains what went wrong.
Connect your application
Your app needs four values: host, database name, username and password. On the same hosting account the host is localhost. Laravel and most frameworks read them from .env:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=myuser_shop
DB_USERNAME=myuser_shopapp
DB_PASSWORD=your-strong-password
WordPress keeps them in wp-config.php as DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Keep .env outside public_html (or blocked from the web) and never commit it to Git.
Test the login over SSH before you blame the app:
mysql -u myuser_shopapp -p myuser_shop -e "SELECT 1;"
Arabic text needs utf8mb4
For Arabic content and emoji, tables need the utf8mb4 character set, for example with collation utf8mb4_unicode_ci. Current WordPress and Laravel create tables that way, but an old SQL dump may use latin1 or utf8, which turns Arabic into ????. Check and change it in phpMyAdmin under Operations → Collation. More in utf8mb4.
Import an existing database
In phpMyAdmin select the database, open Import, choose the .sql file and click Import. Large files are more reliable over SSH:
mysql -u myuser_shopapp -p myuser_shop < backup.sql
Troubleshooting
Access denied for user(1045): wrong password, a missing prefix in the name, or the user was never added to the database. Repeat step 3. See MySQL error 1045.- “Error establishing a database connection” in WordPress: compare the four values in
wp-config.phpwith the panel, character by character (full fix). Can't connect to local MySQL server(2002): the host is wrong. Uselocalhost, not your domain or IP.Access denied ... to databasewhen runningCREATE DATABASE: expected on shared hosting. Create the database from the panel instead.- Import stops or times out: the file is too big for a browser upload. Use the SSH command above, or split the dump.
- Arabic shows as question marks: the table or the connection isn’t
utf8mb4. Convert the table and set the connection charset toutf8mb4in the app.
On ArabyHost
The hosting, WordPress, WooCommerce and AI/Developer plans all include MySQL/MariaDB databases. The Databases tab in the Araby Panel creates a database and its user in one step and shows the password once (we don’t keep a copy), and Quick access opens phpMyAdmin without a password. You can also ask Araby AI to “create a database and write it to my .env”: it writes the details into the file after your approval, without seeing the password. SSH and uapi are available on the AI/Developer plans, and every account is backed up daily with JetBackup.
FAQ
Why does cPanel add my username before the database name?
cPanel prefixes every database and database user with the account name, so `shop` becomes something like `myuser_shop`. That keeps names unique on the server. Always use the full prefixed name in your app's settings.
Which host should my app use to connect?
Use `localhost` when the site and the database are on the same hosting account, which is the normal case. Only a connection from another server needs a different host and the Remote Database Access page.
Can I create a database with an SQL CREATE DATABASE command?
Not on cPanel hosting: database users don't have that privilege. Create the database from cPanel, the Araby Panel or the `uapi` command over SSH, then create tables with SQL as usual.