To import local SQL files into a MySQL database, follow these steps:
Open Command Line or Terminal:
Access your system's command-line interface (CLI).
Navigate to the SQL File Directory:
Use the cd command to go to the folder where your SQL file is stored. For example:
cd /path/to/your/sql/file
Run the MySQL Import Command:
Use the mysql command to import the file. The basic syntax is:
mysql -u [username] -p [database_name] < [file_name.sql]
Replace [username] with your MySQL username, [database_name] with the target database, and [file_name.sql] with your SQL file name.
Example:
mysql -u root -p my_database < backup.sql
You’ll be prompted to enter your MySQL password.
Alternative: Import via MySQL Workbench (GUI):
.sql file.Ctrl+Shift+Enter) to execute the script.Using Tencent Cloud Services:
If you're using Tencent Cloud Database MySQL, you can import SQL files via:
mysql command as shown above, ensuring your Tencent Cloud MySQL instance is accessible (check firewall rules and endpoints).For large files, consider using Tencent Cloud Data Transmission Service (DTS) for efficient migration.