How to Import a MySQL Database?

For importing a database, we  alsouse the mysqldump command or the MySQL Workbench.

MySQL Workbench

In the MySQL Workbench go to Server and select the import option.

This opens the Import utility. In the Import utility, we need to select the folder with the dump file. After selecting the Folder, click on the “Load contents” button. This will load all the dump files we have present in the folder.

If the dump file contains only the data but not the schema name, we need to specify the schema_name. Otherwise, the schema name is not necessary. Once we select all the options necessary, we can just click on the “Start import” button and the database schema will be loaded into our database for us.

MySQL import using the command line:

To import a database using the command-line client, we do the following.

  • Log in to the command line client and create a new database.
  • Once a database is created, close the command line client.

  • Open a command prompt and type in the command:
mysql -u [username] -p [database-name] < [Dump file name and location]

Example:

mysql -u root -p testing < C:\dumps\sakila_dump.sql

This prompts you for the password. Then based on the dump file, the database data is imported into the new database.