导出
1.我们先改一个文件 /etc/my.cnf
[mysqld]
secure_file_priv =
2.创建一个目录,把属组属主改成mysql,然后重新启动mysqld.
[root@localhost ~]# mkdir /backup
[root@localhost ~]# chown -R mysql.mysql /backup
[root@localhost ~]# systemctl restart mysqldd
3.最后一步导出
mysql> select * from t2 into outfile '/backup/a.txt';
[root@localhost backup]# cat a.txt
1 qq
2 qqq
3 wq
4 wr
导入
1.在数据库中创建一个表test;
mysql> create table test(name char(255));
2.把要导入的文件cp 到 /backup目录下面,把b.txt文件属主,属组都改为mysql,权限改为777.
[root@localhost ~]# cp -r /etc/passwd /backup/b.txt [root@localhost ~]# cd /backup [root@localhost backup]# ll 总用量 8 -rw-rw-rw-. 1 mysql mysql 21 7月 3 19:28 a.txt -rw-r--r--. 1 root root 1102 7月 3 19:54 b.txt
[root@localhost backup]# chown -R mysql.mysql /backup/b.txt
[root@localhost backup]# chmod 777 b.txt
[root@localhost backup]# ll
总用量 8
-rw-rw-rw-. 1 mysql mysql 21 7月 3 19:28 a.txt
-rwxrwxrwx. 1 mysql mysql 1102 7月 3 19:54 b.txt
3.导入文件
mysql> load data infile '/backup/b.txt' into table p1 fields terminated by ' ' lines ter
minated by '
';Query OK, 24 rows affected (0.00 sec)
Records: 24 Deleted: 0 Skipped: 0 Warnings: 0