os: centos 7.4.1708
db: mysql 8.0.19
版本
[root@node2 ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[root@node2 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.19 |
+-----------+
1 row in set (0.00 sec)
創建基礎表
mysql> create table tmp_t0 (
id int not null,
name varchar(100),
memo varchar(100),
primary key (id)
)
;
mysql> insert into tmp_t0(id,name,memo)
values(1,'a','aa'),(2,'b','bb'),(3,'c','cc'),(4,'d','dd'),(5,'e','ee');
select into outfile
mysql> select * from tmp_t0 into outfile '/tmp/tmp_t0.sql';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
mysql> show global variables like '%secure_file_priv%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.00 sec)
mysql> select * from tmp_t0 into outfile '/var/lib/mysql-files/tmp_t0.sql';
load data infile into
mysql> create table tmp_t1 as select * from tmp_t0 where 1=2;
mysql> load data infile '/var/lib/mysql-files/tmp_t0.sql' into table tmp_t1;
mysql> select * from tmp_t1;
+----+------+------+
| id | name | memo |
+----+------+------+
| 1 | a | aa |
| 2 | b | bb |
| 3 | c | cc |
| 4 | d | dd |
| 5 | e | ee |
+----+------+------+
5 rows in set (0.00 sec)
參考:
https://dev.mysql.com/doc/refman/8.0/en/load-data.html