MySQL batch SQL statement and mysql batch SQL statement
MySQL supports batch processing to execute a batch of SQL statements. The following example shows how MySQL executes SQL statements in windows batch processing.
Create table test (id int, name varchar (20 ));
Insert into test values (1, 'watson ');
Batchfile.txt contains the following SQL statements, which are stored in c:/batchmysql/batchfile.txt of windows.
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
Insert into test select * from test;
In the cddl database, run the following statements in batches:
Mysql-uroot-p-D cddl <c:/batchmysql/batchfile.txt
Below is the query information contained in the batch processing, and the output is saved to a file:
The corresponding batchfile2.txt contains query information (the following three SQL statements). The following mysql0716.out records the select * from test limit 200; query statement result set.
Select * from test limit 200;
Insert into test select * from test;
Insert into test select * from test;
You can catch the output in a file for further processing:
Mysql-uroot-p-D cddl <c:/batchmysql/batchfile2.txt> c:/batchmysql/mysql0716.out
Batch Processing * bat execution of mysql statements
@ Echo off
If not exist d: \ rank. SQL more + 5% 0> d: \ rank. SQL
Echo> nul
Mysql-h localhost-u root-p 123456 <d: \ rank. SQL
Goto: eof
Truncate table a_rank;
Insert into a_rank (usersn, totalpoint, point );
Select usersn, 0, Ji from ccc order by Ji desc limit 99;
Update a_rank set usernick = (select usernick from B. userinfo where usersn = a_rank.usersn );
Truncate table a_rank;
In the WIN2000 + APMSERV environment, how does one regularly run SQL statements using batch files? (Value-added)
This batch processing can use mysql.exe, which is self-contained by mysql.
@ Echo off
Mysql-u root-p123456-D "test"-e "show databases ;"
Pause
SQL jobs are something that comes with the database software similar to task plans.
=. =! -E "here you can write the SQL statement you want to run"
For example,-e "select 'name' from 'xxx' where 'id' = 1 ;"
I will explain the following parameters to you:
-U User Name
-P password (do not have spaces between-p and password. Note !)
-D "test" can be used to connect to or not, but the SQL statement must include the name of the database to be processed.
-E "SQL statement to run"
You can enter mysql -? Check mysql parameters. I remember a parameter for running SQL statements in the text, that is, reading the statements in the file to run, but I forgot to use it much. -? .