Home > Database > Mysql Tutorial > body text

MySQL文本文件导入及批处理模式应用说明

WBOY
Release: 2016-06-07 18:05:20
Original
973 people have browsed it

MySQL文本文件导入及批处理模式应用说明,需要的朋友可以参考下。

1 将文本文件中的记录载入mysql数据库表中
(1)文本文件格式:每行一条记录,字段值用tab定位符分开,字段顺序和表定义中的顺序一致;对于不确定的字段值用\N表示;
(2)LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;
注意:如果用的是windows的编辑器,应该使用:
LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet
LINES TERMINATED BY '\r\n';

2 模式下运行mysql
(1)把想要运行的mysql语句放在一个文本文件batch-file.txt中;
(2)执行:mysql -h host -u user -p (3)将输出重定向至文件out.txt:
mysql -h host -u user -p out.txt;
从mysql提示符运行脚本:
mysql> source batch-file.txt;或者mysql> \. batch-file.txt;
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template