Databases

CloudPanel v1 is obsolete

CloudPanel v1 is obsolete; check out the CloudPanel v2 Docs.

Adding a Database

To add a new Database, click on the button Add Database top right.

Enter the Database Name, Database User Name, and the Database User Password and click on the button
Add Database.

Adding a Database User

To add a new Database User click on the Database and on the button Add User top right.



If you need a Database User which should only have read permissions, select Read-Only in the Permissions drop down.

Deleting a Database User

On the database overview site, you can delete a Database by clicking on the button Delete.

Master Database Credentials

To see the Master Database Credentials, do the following:

1) Login via SSH to your server and become root.

sudo su root

2) Run the following command:

clpctl db:show:credentials

The Output will look like:



Master Password

The Database Master Password is unique for each CloudPanel and will be created during the initialization.

Managing Databases

The Databases can be managed with phpMyAdmin. On the database overview, click on the tab phpMyAdmin to manage your Databases.

If you don't want to provide access to your CloudPanel, you can give direct access to phpMyadmin.

phpMyadmin Direct Url

https://serverIpAddress:8443/pma

Database Backups

All databases will be automatically backup once per night at 4:15 AM.

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 server and become root.

sudo su root

2) Switch the user to clp-admin.

sudo su clp-admin

3) Edit the Cron Jobs of the user.

crontab -e

4) Change the backup task schedule to your needs.

15 4 * * * clpctl db:backup --databases=all --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.

Create a Backup

To make a backup of all Databases or a specific Database, first login via SSH.

The Database Backups can be found in the directory: /home/cloudpanel/backups/$databaseName/

To backup all Databases, run the following command:

clpctl db:backup --databases=all

The Output will look like:



To backup a specific Database, run the following command:

clpctl db:backup --databases=$databaseName
tip

Multiple databases can be backuped at once via comma e.g.

clpctl db:backup --databases=$database1,$database2,$database3

Database Backup Program

For the backup, CloudPanel uses the Database Backup Program mysqldump from MySQL.

Restore a Backup

For restoring a Database Backup, you can use the CloudPanel CLI or the mysql command:

Restore via CloudPanel CLI

1) Login via SSH to your server.

2) Go to the directory where your Database Dump is e.g.:

cd /home/cloudpanel/backups/wordpress/YYYY-mm-dd/

3) Run the following command to restore the Database Dump:

clpctl db:import --file=dump.sql.gz --database=database-name

Restore via MySQL

The CloudPanel CLI command uses the mysql command for restoring the database under the hood.

To restore a Database Dump via normal mysql command, do the following:

1) Login via SSH to your server and become root.

sudo su root

2) Get the Master Database Credentials with the following command:

clpctl db:show:credentials

The Output will look like:



3) Run the mysql command to restore a gzipped Database Dump.

gunzip < dump.sql.gz | mysql -h'127.0.0.1' -P'3306' -u'root' -p'rGLEUUy6o2Wa7eBN' database-name

A non-gzipped Database Dump can be imported with the following command:

mysql -h'127.0.0.1' -P'3306' -u'root' -p'rGLEUUy6o2Wa7eBN' database-name < dump.sql
Warning

Do not use phpMyAdmin for exporting and importing a database, it can damage your database.
Use mysqldump for exporting a database and the mysql command for import.

Download a Backup

All database backups can be found in the following directory: /home/cloudpanel/backups/

You can download a single Database Backup via SCP, rsync, or via CloudPanel.

To download a backup via CloudPanel, click on the database and on then the tab Backups.

Click on the button Download to start the download process.