Ask Your Question
2

How can multiple SQL files be run in a batch in MySQL?

asked 2023-06-19 12:04:23 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-19 12:27:02 +0000

devzero gravatar image

There are a few different ways to run multiple SQL files in batch in MySQL:

  1. Use the source command: Start by opening the MySQL command-line tool and logging in to your database. Then, use the "source" command to run each SQL file, like this:
mysql> source /path/to/file1.sql;
mysql> source /path/to/file2.sql;
  1. Use a script: You can also create a shell script that runs multiple SQL files at once. Here's an example:
#!/bin/bash

mysql -u your_username -p your_password your_database < /path/to/file1.sql
mysql -u your_username -p your_password your_database < /path/to/file2.sql

Make sure to replace "yourusername" and "yourpassword" with your MySQL login credentials, and "your_database" with the name of your database.

  1. Use a tool: There are also various third-party tools and plugins that can automate running multiple SQL files in batch. For example, MySQL Workbench allows you to create and save a script that runs multiple SQL files in order.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-19 12:04:23 +0000

Seen: 12 times

Last updated: Jun 19 '23