To import a MariaDB database using mysqldump, you first need to ensure you have a dump file (typically a .sql file) created by mysqldump. Here’s the step-by-step process:
Prepare the Dump File:
If you don’t already have a dump file, create one using:
mysqldump -u [username] -p [database_name] > backup.sql
Replace [username] and [database_name] with your MariaDB credentials and database name.
Import the Dump File:
Use the mysql command (not mysqldump) to import the data:
mysql -u [username] -p [database_name] < backup.sql
This reads the SQL statements from backup.sql and executes them on the specified database.
Example:
mysql -u root -p my_database < backup.sql
Enter your password when prompted.
Note:
mysql -u root -p -e "CREATE DATABASE my_database;"
For MariaDB on Tencent Cloud, you can use TencentDB for MariaDB to manage backups and imports. The process remains the same, but you can also leverage Tencent Cloud’s Database Backup Recovery feature for automated backups and restorations.