Introduction
Before you import or restore a database using mysqldump, you would need to ensure you have already created a MySQL database and MySQL database user. You can create both by accessing into "cPanel -> MySQL Databases."
Before importing a database you want to make sure that you SQL dumps are complete. A quick method to check the SQL file integrity is using the following command to view the starting and ending lines of the dump.
(head;tail) < /$PATH/$TO/$DUMP.sql
A working example should look like this. If your dump file is not properly terminated nor has a proper header, then your file may be incomplete or corrupted.
[root@the ~]$ (head;tail) < /root/test.sql
-- MySQL dump 10.13 Distrib 5.7.34, for Linux (x86_64)
--
-- Host: localhost Database: cptest_test
-- ------------------------------------------------------
-- Server version 5.7.34
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2021-05-19 21:47:45
For reference: cPanel docs: MySQL® Databases
Procedure
After both have been created, you can import the database file with mysql command:
mysql -u database_username -p database_name < databasebackupfilename.sql
Comments
0 comments
Article is closed for comments.