Batch processing is a way to run a MySQL program that is not interactive, and you will still use these commands, just as you would for the commands you use in MySQL.
In order to implement batch processing, you redirect a file to a MySQL program, first we need a text file that contains the same text as the command we entered in MySQL.
For example, we want to insert some data, use the file containing the following text (file name New_data.sql, of course, we can also be named New_data.txt and any other legitimate names, not necessarily after the end of the suffix SQL):
Use Meet_a_geek;
INSERT into Customers (customer_id, last_name) VALUES (NULL, "block");
INSERT into Customers (customer_id, last_name) VALUES (NULL, "Newton");
INSERT into Customers (customer_id, last_name) VALUES (NULL, "Simmons");
Note that the syntax of the above sentences must be correct, and each sentence ends with a semicolon. The use command above selects the database and inserts the data into the Insert command.
Below we will import the above file into the database, before importing to confirm that the database is already running, that is, the mysqld process (or service, Windows NT hereinafter referred to as "services", UNIX is "process") already running.
Then run the following command:
Bin/mysql–p
Then press the prompt to enter the password, if the statement in the above file does not have errors, then the data is imported into the database.
The command line uses the load data INFILE to import data from a file into the database:
Now you might ask yourself, "Why on earth do I have to enter all these SQL statements into a file and then run them through the program?" ”
It looks like it's going to take a lot of work. Well, you're probably right about that. But what if you have log records from all of these commands? Now that's great, well, most databases will automatically generate log of event records in the database. Most log contains the original SQL commands that are useful. So, if you can't export data from your current database to a new MySQL database, you can use the log and MySQL batch features to quickly and easily import your data. Of course, this eliminates the trouble of typing.