Dung (Donny) Nguyen

Senior Software Engineer

Import Database into MySQL

To import a database into MySQL from a .sql file, you can use one of the following methods depending on your environment:


🖥️ Method 1: Using the MySQL Command Line

mysql -u username -p database_name < path/to/your/file.sql

🧰 Method 2: Using MySQL Workbench

  1. Open MySQL Workbench and connect to your server.
  2. Go to File > Open SQL Script and select your .sql file.
  3. The script will open in a new tab. Click Execute (lightning bolt icon) to run it.
  4. Alternatively, use Server > Data Import and choose “Import from Self-Contained File”.

🐳 Method 3: Inside a Docker Container

If you’re using MySQL in Docker:

docker exec -i mysql-container-name mysql -u username -p database_name < file.sql

🧪 Bonus Tips