数据的导出导入,最常用的方法:
导出:
SET NAMES "utf8"
select * from ricci_var into outfile‘/tmp/var.csv‘ fields terminated by ‘,‘ optionally enclosed by ‘"‘ lines terminated by ‘\n‘
导入:
SET NAMES "utf8"
load data infile "/tmp/var.csv"into table ricci_var fields terminated by ‘,‘ optionally enclosed by ‘"‘ lines terminated by ‘\n‘
在某些特殊的情况下,是无法这么操作的,如垃圾的RDS,就需要这么操作了:
导出:
usr/local/mysql/bin/mysql -h192.168.1.10 -udlan -proot123 test -e" SELECT * FROM manufactor_user_info where date(create_time)<=‘2017-05-02‘" -N -s |sed ‘s/\t/","/g;s/^/"/;s/$/"/;s/\n//g‘> /tmp/test.csv 导入: SET NAMES "utf8" load data infile ‘/tmp/test.csv‘ into table manufacturer_log fields terminated by ‘,‘ optionally enclosed by ‘"‘ lines terminated by ‘\n‘ ###具体的导出条件自己懂的。在导出的数据需要进行简单的清洗,有可能会碰到某某行的数据段数据错误或者定义错误这样的提示.Wrong data or column definition. Row: 69697, field: 43. 这样的提示主要是由于数据存在问题的需要清洗,从MYSQL导入infobright 会这样提示,可以设置 SET @BH_REJECT_FILE_PATH = ‘/tmp/reject_file‘; SET @BH_ABORT_ON_COUNT = 10;(自定定义错误条数) 可以通过这个观察数据问题所在。 再者就是导出的时候,有权限问题,如: ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement 解决办法: 1. 设置安全目录: vi /etc/my.cnf secure-file-priv=/home/自己的目录/ 2. 有权限写入目录/home/自己的目录/ (5.7的需要设置)
再办法是:
mysqldump 导成SQL文件
最后办法:
导出:mysql -udlan -proot123 --database=test --execute=‘SELECT a, b FROM aaa LIMIT 0, 10000 ‘ -X > file.csv
导入:
SET NAMES "utf8"
load xml infile ‘/tmp/file.csv‘ into table user_info1
时间: 2024-12-14 18:58:34