Mysql import multiple sql files

To export or import with MySQL, begin by logging into your server, preferably with sudo (root) access.

Exporting from MySQL

The best tool for exporting a MySQL database to a text file is mysqldump.

To use mysqldump, you will need to know the login credentials of an appropriate MySQL user that has the necessary privileges to export the database in question.

With that information in hand, enter the mysqldump command with the appropriate flags and options:

$ mysqldump -u my_username -p database_name > output_file_path

The options in use are:

  • The -u flag indicates that the MySQL username will follow.
  • The -p flag indicates we should be prompted for the password associated with the above username.
  • database_name is of course the exact name of the database to export.
  • The > symbol is a Unix directive for STDOUT, which allows Unix commands to output the text results of the issued command to another location. In this case, that output location is a file path, specified by output_file_path.

Note: It is generally advisable to input the fully qualified path and filename for the output_file_path, so the resulting file is generated exactly where you want it.

For example, to export the books database as the book_admin user to the ~/backup/database directory, we might use the following command:

$ mysqldump -u book_admin -p books > ~/backup/database/books.sql
Enter password:

After entering our password when prompted above, this command then creates our backup file with a .sql suffix (which is completely optional but advisable) in the appropriate directory.

By default, mysqldump will not save commands which attempt to modify the existence of the actual database. Instead, by default, only actual tables (and their respective data) are saved and thus will be prepared for later import using this file. If you need the ability to export (and later recreate) one more more databases, read up on the --databases flag in the official documentation.

Importing Into MySQL

Now that you’ve learned how to export a backup of a MySQL database, we’ll explore how to reverse the process and import the backup into an existing database.

As you might imagine, to compliment the mysqldump command used for exporting, there is a similar mysqlimport command for importing.

In most cases, importing is just a matter of passing virtually identical options to the mysqlimport command. To import our saved books.sql file created earlier, we’d use many of the same flags and much the same syntax.

$ mysqlimport -u book_admin -p books_production ~/backup/database/books.sql
Enter password:

As before, the -u and -p flags are required for authentication, which is then followed by the name of the database to import into (in this case, we’re using different, production database), then lastly specifying the fully-qualified path to the SQL dump file that contains our import data, ~/backup/database/books.sql. It’s also worth noting that mysqlimport doesn’t require the < or > (STDIN/STDOUT) symbols that were used with mysqldump.

With that, you’ve learned how to both export/backup an existing database, and how to then import/restore that data into the same or even a different database.

Have you just begun to learn how to work with SQL files using MySQL?
Maybe you feel a bit lost on how to import files with this tool.
Luckily, importing and exporting files via MySQL is actually quite simple.

Learn how to use MySQL to import SQL files by following the step-by-step guide below.

Looking for simple service to manage your MySQL backups?
→ Try SimpleBackups for free

Table of Contents

Import an SQL file using Command Line

Using XAMPP (or skip to Command line import)

  1. Open XAMPP.
  2. Launch Apache Server and MySQL Database.
  3. Create a database via phpMyAdmin.
  4. Copy the SQL file of your choice to the xampp/mysql/bin/ directory.
  5. Open Command Prompt.
  6. Go to xampp/mysql/bin/.

Command line MySQL import

  1. Type: mysql -u username -p database_name < file.sql
  2. The username refers to your MySQL username.
  3. database_name refers to the database you want to import.
  4. file.sql is your file name.
  5. If you've assigned a password, type it now and press Enter.

Verify your data

  1. Open phpMyAdmin or any MySQL client and select your database to ensure that the tables have imported properly.

Import a SQL file using mysqldump

  1. To import a .sql file with mysqldump, use the mysqlimport command and use the following flags and syntax $ mysqlimport -u magazine_admin -p magazines_production ~/backup/database/magazines.sql
  2. -u and -p are needed for authentication, and is then followed by the name of the database you want to import into.
  3. You'll need to specify the path to your SQL dump file that will contain your import data: ~/backup/database/magazines.sql
  4. You won't need to use > or < for importing, but you will need them for exporting in the next guide.
  5. This will prompt a password request.
  6. Your file will be automatically imported.

Notes:

  • After entering this command, you may be asked to enter the password for the MySQL user that you used.
  • Please be careful when using an existing database that has records as this command will overwrite your existing database and end up losing your records.

Export an SQL file using mysqldump

  1. To export a MySQL database to a test file, start by using the mysqldump command.
  2. Log in to MySQL.
  3. Enter the mysqldump command using the following flags and options: $ mysqldump -u my_username -p database_name > output_file_path
  4. The -u flag specifies the MySQL username.
  5. The -p flag specifies a password prompt associated with the above username.
  6. database_name is the name of the database you want to export.
  7. The > symbol is a Unix directive for STDOUT, which will make it possible for Unix commands to output the subsequent results of the output command to another location. These locations are usually file paths.
  8. Be sure to input the completely qualified path and its filename to your output file path, so that your file will be placed exactly where you want it to be.
  9. Once the command is executed, you'll be prompted to enter your password. This will then create your exported backup file with a .sql extension.

How to automate your MySQL backups?

Making MySQL backups and restoring a MySQL dump (like addressed in this article) is not a complicated task but comes a moment when you'll want to automate it in a way where you can trust your data is secure 100% of the time.

When you have to manage multiple backups, on multiple servers and want a solution you can trust with orchestrating it all in an optimized way, make sure to check out what we do at SimpleBackups.
SimpleBackups automates MySQL backups to securely send backup files offsite to the cloud for storage.

How do I import multiple SQL files into MySQL workbench?

Import Multiple SQL files to Database by using Data Import/Restore in MySQL Workbench is great feature when you need to import multiple SQL files into MySQL Server. If you have created multiple files by using Data Export feature in MySQL Server, SQL Dump file project can be imported by using MySQL Import/Restore.

How do I combine multiple SQL files into one?

Combining multiple SQL scripts into a single script can be done in a few steps:.
Run ApexSQL Build..
Click the Consolidate button from the Home tab:.
Choose SQL as an output type:.
Add script files that should be combined..

How do I import multiple CSV files into MySQL workbench?

Contents.
Create data import templates..
Create a text file with the list of import templates..
Create a .bat file to run the import job..
Populate the database from CSV files via the command line..
Schedule a bulk insert from the command-line..

How do I open multiple .SQL files in one SSMS instance?

How to open multiple ..
Right click on the . ... .
Perfomed Run > regedit > and modify the value data of HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command and replace /dde with "%1". ... .
Right click on the . ... .
Some pages like this..