Mysql利用命令导入导出数据-备份和恢复
一、配置
可能会遇到的问题
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
解决
windows10修改方式
修改mysql配置文件my.ini
,在文件中直接添加secure_file_priv="G:\"
-
secure_file_priv=null 不允许文件的导入导出
-
secure_file_priv=xxx 文件导入导出到某路径
-
secure_file_priv=/ 文件可 导入到任意路径
二、导入
load data infile '导入源' into table 需要导入的表 fields terminated by ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
load data infile
恢复表数据命令
fields terminated by '\r\n'
每条记录末尾添加该字符串,默认换行符号“\n”
OPTIONALLY ENCLOSED BY '"'
字段引用符,负责向字段值两边加上字段引用符
fields terminated by
字段引用符,负责向字段值两边加上字段引用符
三、导出
select * from 需要导出的表 into outfile '导出文件地址' fields terminated by ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
select *** into outfile ***
备份表数据
其他命令同导入功能一样
四、总结
通过命令导出1500w数据总共花费时间15分钟左右,导入用时比较慢800w数据导入用时40分钟左右,总体比直接用navicat工具导入导出要快很多。特别需要注意命令导入的格式。