Home  >  Article  >  Database  >  MySQL批处理SQL语句

MySQL批处理SQL语句

WBOY
WBOYOriginal
2016-06-07 16:50:301520browse

MySQL 支持批处理的模式执行一批SQL语句,下面的例子就是实验MySQL如何在windows下批处理执行SQL语句。

MySQL 支持批处理的模式执行一批SQL语句,下面的例子就是实验MySQL如何在windows下批处理执行SQL语句。
 
create table test(id int,name varchar(20));
 insert into test values(1,'watson');
 
 
batchfile.txt里包含下面的一些SQL 语句,此文件放在windows系统的c:/batchmysql/batchfile.txt
 
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;
 
 
在cddl数据库里进行批执行上面的语句如下:
 mysql -uroot -p -D cddl  
 
下面是把批处理里含有查询的信息,输出保存到一个文件里:
 
此时的batchfile2.txt里含有query的信息(下面的3条SQL语句),,下面的mysql0716.out就记录了select * from test limit 200;查询语句的结果集。
 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/mysql0716.out

--------------------------------------分割线 --------------------------------------

Ubuntu 14.04下安装MySQL

《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主从服务器

Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群

Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb

--------------------------------------分割线 --------------------------------------

本文永久更新链接地址:

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn