MySQL SELECT xxx INTO OUTFILE用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL SELECT xxx INTO OUTFILE用法相关的知识,希望对你有一定的参考价值。

1、导出数据报错 mysql> SELECT * INTO OUTFILE ‘/tmp/t.txt‘ FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘ ‘ FROM t; ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement mysql> show variables like ‘%secure%‘; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | require_secure_transport | OFF | | secure_auth | ON | | secure_file_priv | NULL | +--------------------------+-------+ 3 rows in set (0.01 sec) mysql> 2、解决方法,需要重启数据库 [mysqld] secure_file_priv=‘‘ 3、重新导出,OK mysql> SELECT * INTO OUTFILE ‘/tmp/t.txt‘ FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘ ‘ FROM t; Query OK, 2 rows affected (0.00 sec) mysql> 4、查看验证 [[email protected] ~]$ cat /tmp/t.txt 1,"a" 2,"b" [[email protected] ~]$ 5、导入成功 mysql> LOAD DATA INFILE "/tmp/t.txt" INTO TABLE trsids.t FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘ ‘ -> ; Query OK, 2 rows affected (0.01 sec) 6、验证数据OK mysql> select * from trsids.t; +------+------+ | id | name | +------+------+ | 1 | a | | 2 | b | | 1 | a | | 2 | b | +------+------+ 4 rows in set (0.00 sec) mysql>

以上是关于MySQL SELECT xxx INTO OUTFILE用法的主要内容,如果未能解决你的问题,请参考以下文章

MySQL select into 和 SQL select into

MySQL存储过程中使用SELECT …INTO语句为变量赋值

SELECT * INTO <不存在的表>-MYSQL [重复]

MYSQL insert into select 锁表问题

select into 在mysql中失效的替换办法

MySQL复制表-INSERT INTO SELECT