mysql (on a cPanel server root reads its details from /root/.my.cnf), then SHOW DATABASES;, USE db_name; and SHOW TABLES;. To create a database and user: CREATE DATABASE, CREATE USER, then GRANT. On a cPanel server, create them in cPanel so they appear in its interface.Logging in #
| Case | Command |
|---|---|
| root on a cPanel server | mysql directly |
| A specific database user | mysql -u user_db -p user_dbname, then the password |
| A server without a panel | mysql -u root -p |
Commands you use every day #

| Command | What it does |
|---|---|
SHOW DATABASES; |
Every database |
USE example_wp; |
Pick a database |
SHOW TABLES; |
Tables in the chosen database |
DESCRIBE wp_users; |
A table’s columns |
SELECT COUNT(*) FROM wp_posts; |
Row count |
SHOW PROCESSLIST; |
Queries running now |
EXIT; |
Leave |
Worked example: WordPress URL after a move #
USE example_wp;
SELECT option_name, option_value FROM wp_options
WHERE option_name IN ('siteurl','home');
UPDATE wp_options SET option_value='https://example.com'
WHERE option_name IN ('siteurl','home');
Watch the table prefix: it is not always wp_. Find it in wp-config.php.
Creating a database and user #
CREATE DATABASE app_db; CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'StrongPass#2026'; GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost'; FLUSH PRIVILEGES;
Common errors #
| Message | Cause |
|---|---|
Access denied for user |
Wrong password, or the user has no rights on this database |
Unknown database |
Wrong name; remember the prefix, such as user_dbname |
ERROR 1064 |
A syntax error, usually a comma or quote |
Can’t connect to local server through socket |
The database service is stopped. Restart it as in restarting services |
To import a large file or export a copy, see importing and exporting over SSH.
A quick copy before any change #
Before any UPDATE or DELETE on real data, copy the table inside the database in a second:
CREATE TABLE wp_options_backup AS SELECT * FROM wp_options; -- once the change is confirmed: DROP TABLE wp_options_backup;
If something goes wrong, restore with INSERT from the backup table. This small habit saves many sites from a hasty command missing its WHERE clause.
MySQL questions #
Where is the database root password on cPanel?
In /root/.my.cnf, which is why mysql works directly for root. Do not share it.
Can UPDATE and DELETE be undone?
No. Copy the table or database before any bulk change.
Are the commands the same in MariaDB?
Yes, the basics are identical.
How do I see each database’s size?
With a query on information_schema that sums table sizes per database, or from WHM’s database tools.
- How to Import a Large MySQL Database over SSH
- Connecting to a MySQL Database from Outside the Server: WHM, cPanel Remote Database Access and the Firewall
- Upgrading MySQL or MariaDB on a cPanel Server with Upgrade Database Version: The Five Steps and What Cannot Be Undone
- Connecting to Your Server Remotely with SSH: From Windows, macOS and Linux, and SSH Keys Instead of Passwords