参考链接
//导出方法
//第一种方法,控制台下直接使用 加-N表示不导出表头
mysql -uuser -ppassword -N -e "set names utf8;select * from dbname.tablename limit 5" |sed -e "s/\t/,/g" -e "s/NULL/ /g" -e "s/\n/\r\n/g" > /var/lib/mysql-files/test.csv
//第二种方法,这个需要登陆mysql后进行执行命令,这个手动
select * from tablename limit 3 into outfile "/var/lib/mysql-files/test.log" fields terminated
by ',' optionally enclosed by '"' escaped by '"' lines terminated by "\r\n";
select * from test_info
into outfile '/tmp/test.csv'
fields terminated by ',' ------字段间以,号分隔
optionally enclosed by '"' ------字段用"号括起
escaped by '"' ------字段中使用的转义符为"
lines terminated by '\r\n'; ------行以\r\n结束
//导入方法
mysqldump -uusername -p databases> /home/usersystem.sql
网友评论