CleverCode在实际的工作中,经常需要将一些报表,或者日志数据等导出来,如果直接做页面,如果次数也不是很多,需求也不同。所以直接导出csv文件,更加直观。
into outfile ‘目标文件’,目标文件是保存在mysql的服务器端,因为sql语句都是在服务器端执行了。所以执行完后目标文件会保存在mysql服务器端。into outfile '/tmp/test.csv',一般是mysql服务器是在linux上;into outfile 'E:/test.csv' ,一般是mysql服务器端在windows上。并且目标文件必须有写入权限,而且文件不能存在。
select * from proxy_list order by id asc limit 0,2 into outfile '/tmp/test.csv' fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';
select uid, nation from system_user order by uid asc limit 0,2 into outfile 'e:/test.csv' fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';