大头

mysql导入导出文本文件

MySQL导入出文本文件只能到处数据,不能到处结构,不过也算备份数据一种方法。

导入文本文件

在此像导入csv文件 也是类似

load data local infile 'd:/insert.txt'  into table test;

文本文件,注意:默认字段之间的用 tab键做空格,如果字段为空用  \N 代替

李四    \N
\N    45

导出文本文件

在导出时可能存在问题: 提示错误[Error Code] 1290 - The MySQL server is running with the --secure-file-priv option解决办法

SHOW VARIABLES LIKE "secure_file_priv"    后查看变量得值:

secure_file_prive=null   -- 限制mysqld 不允许导入导出

secure_file_priv=/tmp/   -- 限制mysqld的导入导出只能发生在/tmp/目录下 默认都是这个

secure_file_priv=' '         -- 不对mysqld 的导入 导出做限制

因此直接导入到临时目录下:

select * from test  into outfile 'e:/wamp64/tmp/outfile_3.txt' lines terminated by "\r\n";

lines terminated by ‘\r\n’——每条数据以换行存在

注意

字段之间的分隔和记录(行)之间的分隔默认是\t和\n,但我们可以自己设置。

fileds terminated by  ‘设置分隔符’——字段之间进行分隔

lines terminated by  ‘设置分隔符’——行分隔符

image

posted @ 2017-03-10 14:37  and大头  阅读(697)  评论(0编辑  收藏  举报

大头