1. 程式人生 > >MySQL SELECT xxx INTO OUTFILE用法

MySQL SELECT xxx INTO OUTFILE用法

重啟數據庫 rmi sta off -s int select value sid

1、導出數據報錯 mysql> SELECT * INTO OUTFILE ‘/tmp/t.txt‘ FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘\n‘ 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 ‘\n‘ FROM t; Query OK, 2 rows affected (0.00 sec) mysql> 4、查看驗證 [mysql@roidb01 ~]$ cat /tmp/t.txt 1,"a" 2,"b" [mysql@roidb01 ~]$ 5、導入成功 mysql> LOAD DATA INFILE "/tmp/t.txt" INTO TABLE trsids.t FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘\n‘ -> ; 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用法