MySQLphpMyAdmincPanel5 min read

Manage MySQL databases in cPanel

Create databases, users, permissions, phpMyAdmin, import/export and optimize tables.


Introduction to MySQL in cPanel

MySQL is the most widely used database engine in shared hosting. From cPanel you can create, manage and optimize your databases without needing the command line.

Create a database

  1. Log in to cPanel
  2. Go to DatabasesMySQL Databases
  3. Under "New Database", enter the name
  4. Click Create Database

Create a user

  1. In the same section, scroll down to "MySQL Users"
  2. Enter a username and strong password
  3. Click Create User

Assign permissions

  1. Under "Add User to Database", select the user and database
  2. Click Add
  3. Select privileges (for WordPress, check ALL PRIVILEGES)
  4. Click Make Changes

Access phpMyAdmin

  1. In cPanel → DatabasesphpMyAdmin
  2. Select your database in the left panel
  3. From here you can run SQL queries, view tables and edit records

Import a database

From phpMyAdmin

  1. Select the target database
  2. Click Import
  3. Choose the .sql file (max size depends on server configuration)
  4. Click Go

Via command line (large files)

bash
mysql -u cpanel_user -p database_name < backup.sql

Export a database

  1. In phpMyAdmin, select the database
  2. Click Export
  3. Choose SQL format and Quick method
  4. Click Go
bash
# Via SSH
mysqldump -u username -p database_name > export.sql

Optimize tables

Over time, tables become fragmented. To optimize them:

  1. In phpMyAdmin, select the database
  2. Check all tables
  3. From the dropdown at the bottom, select Optimize table
sql
-- Or via direct SQL
OPTIMIZE TABLE wp_posts, wp_options, wp_postmeta;

Repair corrupted tables

If a table becomes corrupted:

sql
REPAIR TABLE table_name;

-- Check integrity
CHECK TABLE table_name;

Best practices

  • Use a different user for each application
  • Never use the cPanel root user for applications
  • Make regular backups of your databases
  • Limit privileges to the minimum necessary
  • Check your database sizes periodically from cPanel

Was this guide helpful?