1、从文本文件导入数据
mysql> load data [local] infile '/test/file1.txt' into table sinfo fields terminated by
' ' enclosed by '"' escaped by '"' lines terminated by '\r';
fields terminated by 字段分隔符,默认为tab
enclosed by '"' escaped by '"' 每个字段的内容是否放在特定的字符里面,如"姓名"
lines terminated by 每条记录行的分隔符,默认为回车"\n"
练习:将access.log.1文件中的ip地址,访问的协议及状态,传输的字节数,请求方式和访问的url及端口导入到
数据库,并要求在最前面加入编号,从1开始
1222441666.045 0 192.168.20.171 TCP_DENIED/403 1869 CONNECT urs.microsoft.com:443 - NONE/- text/html
提取的内容为:192.168.20.171 TCP_DENIED/403 1869 CONNECT urs.microsoft.com:443
记录的字段为:
id ipaddr pstats fsize method url
1 192.168.20.171 TCP_DENIED/403 1869 CONNECT urs.microsoft.com:443
2、将数据导出为文本文件
mysql> select * from employees into outfile '/test/employees.txt';