導出數據
mysql> select * from stu_info1
-> into outfile '/root/123.txt';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
-- 只能在規定目錄下導出
-- 查看目爲/var/lib/mysql-files/
mysql> show variables like '%secure%';
+--------------------------+-----------------------+
| Variable_name | Value |
+--------------------------+-----------------------+
| require_secure_transport | OFF |
| secure_file_priv | /var/lib/mysql-files/ |
+--------------------------+-----------------------+
2 rows in set (0.02 sec)
mysql> select * from stu_info1 into outfile '/var/lib/mysql-files/123.txt';
Query OK, 5 rows affected (0.03 sec)
-- 查看數據已導出
mysql>
[1]+ Stopped mysql -u root -p
[root@VM_0_11_centos ~]# cat /var/lib/mysql-files/123.txt
1 ztq 1994-12-29 159****0773
2 tqz 1994-11-27 159****0773
3 fq 1994-05-23 187****8793
4 qf 1994-05-23 187****8793
5 12312323 1998-12-12 14
導入數據
mysql> LOAD DATA INFILE '/var/lib/mysql-files/123.txt' INTO TABLE stu_info1;
Query OK, 5 rows affected (0.04 sec)
Records: 5 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from stu_info1;
+----+----------+------------+-------------+
| id | name | birth | tel |
+----+----------+------------+-------------+
| 1 | ztq | 1994-12-29 | 159****0773 |
| 2 | tqz | 1994-11-27 | 159****0773 |
| 3 | fq | 1994-05-23 | 187****8793 |
| 4 | qf | 1994-05-23 | 187****8793 |
| 5 | 12312323 | 1998-12-12 | 14 |
+----+----------+------------+-------------+
5 rows in set (0.00 sec)