Knowledge

Importing database in MySQL using command line

#Databases

Importing a database in MySQL is quick & easy using the command line.

Published by Mark van Eijk on August 30, 2022 · 1 minute read

  1. Different options
  2. Using the command line

Different options

Importing a MySQL database can be done in several ways, using a desktop app or even using the legendary phpMyAdmin!

But the most effective and fast way to import a (large) SQL file remains - as always - using the command line interface (CLI).

Using the command line

Using the command below you can import large SQL files in the least amount of time:

mysql -u [username] -p [database] < import.sql

Replace [username], [database] and import.sql with the correct values in your setup.

To go the other way, see exporting a database. If timestamps shift on import, fix the timezone difference. And to rename a database afterwards, see rename a MySQL database.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!