Databases
Adding a Database
- Click on Add Database to create a new database.
- Enter the Database Name, Database User Name, and Database User Password and click on the button Add Database.
Deleting a Database
To delete a database, click on Delete and confirm your action.
Adding a Database User
- Click on Add Database User to add a new user to your database.
- Enter the Database User Name, Database User Password, and select the Database and the Permissions.
Deleting a Database User
To delete a database user, click on Delete and confirm your action.
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.
Exporting a Database
For exporting a database, CloudPanel uses mysqldump client utility.
To export a database, do the following.
- Login via SSH with the Site User.
ssh site-user@instance-ip-address
- Go to the directory where the database dump should be saved e.g., the tmp directory of the user.
cd ~/tmp/
- Run clpctl to see all available commands.
clpctl
- 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.
- Login via SSH with the Site User.
ssh site-user@instance-ip-address
- Run clpctl to see all available commands.
clpctl
- 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:
- Login via SSH to your instance and become root.
sudo su root
- Open the crontab:
nano /etc/cron.d/clp
- 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.
- Login via SSH to your instance and become root.
sudo su root
- Run the following command:
clpctl db:show:master-credentials
The output will look like this:
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.