使用文件向表中导入导出记录
修改 my.ini
select @@global.secure_file_priv;
mysql> select @@global.secure_file_priv;
+---------------------------+
| @@global.secure_file_priv |
+---------------------------+
| NULL |
+---------------------------+
1 row in set (0.023 sec)
mysql>
[mysqld]
# 允许任何路径都可以导入或导出
secure_file_priv=""
mysql> select @@global.secure_file_priv;
+---------------------------+
| @@global.secure_file_priv |
+---------------------------+
| |
+---------------------------+
1 row in set (0.005 sec)
mysql>
使用文件向表中导入记录
abcdef 小清新
k8899s 龙校长
下面的命令,使得 a.txt 中的两条记录导入到表 wechat:
load data infile 'd:/doc/it/a.txt' into table wechat fields terminated by ' ';
mysql> load data infile 'd:/doc/it/a.txt' into table wechat fields terminated by ' ';
Query OK, 2 rows affected (0.594 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql>
mysql> select * from wechat ;
+--------+----------+
| id | nickname |
+--------+----------+
| bcdef | 小清新
| k8899s | 龙校长
+--------+----------+
2 rows in set (0.006 sec)
mysql>
把表中记录导出到文件
select * into outfile 'd:/doc/it/b.txt' fields terminated by ' ' from wechat;
mysql> select * into outfile 'd:/doc/it/b.txt' fields terminated by ' ' from wechat;
Query OK, 2 rows affected (0.244 sec)
mysql>
abcdef 小清新
k8899s 龙校长