Here are the MySQL import and export commands for Linux via the command line:
Export a MySQL Database (Dump)
To export (dump) a MySQL database to a .sql
file, use:
Options:
-u [username]
→ MySQL username-p
→ Prompt for password[database_name]
→ Name of the database to exportbackup.sql
→ Output file containing the SQL dump
Example:
Import a MySQL Database
To restore/import a MySQL database from a .sql
file:
Example:
If the Database Does Not Exist:
Create it first:
Export & Import with Compression
For large databases, use gzip to compress the export:
Export (Dump & Compress)
Import (Decompress & Restore)
Export & Import Specific Tables
Export a Specific Table
Import a Specific Table
List All Databases
Before importing/exporting, you can list databases using:
Bonus windows server
2. Import Files Using WAMP MySQL CLI
C:\wamp64\bin\mysql\mysql8.0.27\bin\mysql -u username -p database_name < path_to_mysql_file.sql
3. Import Files Using XAMPP MySQL CLI
C:\xampp\mysql\bin>mysql -u username -p database_name < path_to_mysql_file.sql