MySQL batch SQL statement and mysql batch SQL statement

Source: Internet
Author: User

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. -? .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.