Backup and restore database in SSH

1

It is a fact, restore/import dense or important databases by phpmyadmin is not working or bad, it is a software limit related to phpmyadmin. The solution is to talk directly to the mysql server by SSH ...

Ask us first to activate your SSH access, see dedicated article, then connect in SSH with Putty software

Then, by the file manager of your cPanel, create this file at the root of your account: .my.cnf
Then edit this file
Here, we will take as an example a cPanel account whose login is: logindemo and the password: FD5f45d, put this in your .my.cnf file by replacing with the good values:
[customer]
user = logindemo
password = FD5f45d

We now give you an example of manipulation where you must of course replace it with the correct database name ...

To /backup/save an existing database whose name is for example : logindemo_base1, and save it in a file that will be named: logindemo_base1.sql, you will have to type this in putty then entry:
mysqldump logindemo_base1> logindemo_base1.sql
The logindemo_base1.sql backup file is located by default in /.cagefs/root (cloudlinux server), you can either download it or use it to restore in SSH or by cPanel ...

Let's go now to the restoration with SSH of the saved database in order to insert it into an existing database or a new one.
If to an existing database, the restore will overwrite the old data, prefer to delete the old content by phpmyadmin
If to a new database, you must create it by cPanel in advance, and give it a user and his password

Concrete example :
By the following command, we will resume our database file previously saved: logindemo_base1.sql, and import it into a new database named: logindemo_base2
mysql logindemo_base2 <logindemo_base1.sql

NB
- Remember to delete your backup files in /.cagefs/root