Skip to main content

Databases

Adding a Database

  1. Click on Add Database to create a new database.
Adding a Database
  1. Enter the Database Name, Database User Name, and Database User Password and click on the button Add Database.
Add Database Form

Deleting a Database

To delete a database, click on Delete and confirm your action.

Deleting a Database

Adding a Database User

  1. Click on Add Database User to add a new user to your database.
Adding a Database User
  1. Enter the Database User Name, Database User Password, and select the Database and the Permissions.
Adding a Database User Form

Deleting a Database User

To delete a database user, click on Delete and confirm your action.

Deleting a Database User

phpMyAdmin

To manage a database via phpMyAdmin, click on Manage, and you will be forwarded to phpMyAdmin.

Attention

Do not use phpMyAdmin to export and import databases; it can destroy your database.
Use export and import guide from below.

phpMyAdmin

Exporting a Database

For exporting a database, CloudPanel uses mysqldump client utility.

To export a database, do the following.

  1. Login via SSH with the Site User.
ssh site-user@instance-ip-address
  1. Go to the directory where the database dump should be saved e.g., the tmp directory of the user.
cd ~/tmp/
  1. Run clpctl to see all available commands.
clpctl
CLI User Commands
  1. Use the following command to export a database.
Compression

The database dump will be gzipped if you add .sql.gz at the end of the file name. If you want to export the database uncompressed, use .sql.

clpctl db:export --databaseName=my-database --file=dump.sql.gz

Importing a Database

For importing a database, CloudPanel uses mysql command-line client.

To import a database, do the following.

  1. Login via SSH with the Site User.
ssh site-user@instance-ip-address
  1. Run clpctl to see all available commands.
clpctl
CLI User Commands
  1. Go to the database dump's directory and use the following command to import a database.
clpctl db:import --databaseName=my-database --file=dump.sql.gz

Database Backups

CloudPanel creates a dump of each database every night at 3:15 AM with a retention period of 7 days.

All database backups can be found in the backups directory of the site user.

/home/$site-user/backups/

If you have smaller databases, you can change the cron job to run more frequently, like twice a day.

To change the schedule of the database backup task, do the following:

  1. Login via SSH to your instance and become root.
sudo su root
  1. Open the crontab:
nano /etc/cron.d/clp
  1. Change the backup task schedule to your needs.
15 3 * * * clp /usr/bin/bash -c "/usr/bin/clpctl db:backup --ignoreDatabases='db1,db2' --retentionPeriod=7" &> /dev/null
Retention Period

If you want to save the database backups for more than seven days, change the retentionPeriod value.

Database Master Credentials

To see the Master Database Credentials, do the following.

  1. Login via SSH to your instance and become root.
sudo su root
  1. Run the following command:
clpctl db:show:master-credentials

The output will look like this:

Show Database Master Credentials

Copy the Connect Command to get connected to your database server.

Remote Database Access

For a remote connection to your database, go to Firewall in the Admin Area and whitelist your IP for the MySQL port 3306 in the Firewall.