使用sql语句导出数据:
导出时如果不写绝对路径,会提示The server is running with the --secure-file-priv option so it cannot execute this statement。
使用 show variables like "%secure%" 查看secure_file_priv 设置的路径,导出时必须是这个路径才能导出,默认NULL的话是禁止导出的。
导出命令:select id,分数 from score into outfile "/var/lib/mysql-files/score.txt"; (id,分数是列名,score是表名)
加上逗号分隔和引号:select id,分数 from score into outfile "/var/lib/mysql-files/score1.txt" fields terminated by "," enclosed by '"';
使用mysqldump导出文件:mysqldump -T ./ schoolDB score --fields-terminated-by ',' --fields-optionally-enclosed-by '"';
Mysql导出:
mysql -uroot -pxxx --vertical --execute=' select id from score ;' schoolDB > /var/lib/mysql-files/score.txt
[root@hkdlvm00 mysql-files]# cat score.txt
*************************** 1. row ***************************id: 1*************************** 2. row ***************************id: 2*************************** 3. row ***************************id: 3导出时,去掉*****注释:mysql -uroot -pxxx --execute=' select id from score ;' schoolDB > /var/lib/mysql-files/score.txt
id
123导入数据:load data infile '/var/lib/mysql-files/score.txt' into table score ignore 1 lines (班级);
load data infile '/var/lib/mysql-files/score.txt' into table score ignore 1 lines (班级) set 分数=77; (设置分数栏的所有默认值为77)