mysqldump(--tab)参数使用
1.尝试导出整个库
[root@localhost data]# mysqldump --set-gtid-purged=OFF --tab=/tmp/data db_hxl -u root -pmysql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
SET @@SESSION.SQL_LOG_BIN= 0;
--
-- GTID state at the beginning of the backup
--
SET @@GLOBAL.GTID_PURGED='0b23e9fb-0ef2-11e9-8450-525400f3712a:1-32';
mysqldump: Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when executing 'SELECT INTO OUTFILE'
[root@localhost data]#
[root@localhost data]# mysqldump --set-gtid-purged=OFF --tab=/tmp/data db_hxl -u root -pmysql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when executing 'SELECT INTO OUTFILE'
secure-file-priv的值有三种情况:
secure_file_prive=null ––限制mysqld 不允许导入导出
secure_file_priv=/path/ --限制mysqld的导入导出只能发生在默认的/path/目录下
secure_file_priv='' --不对mysqld 的导入 导出做限制
2.修改初始化参数加入如下项
secure_file_priv=''
3.重启动
[root@localhost ~]# mysqladmin -h localhost -uroot -pmysql shutdown
/opt/mysql5730/bin/mysqld --defaults-file=/opt/mysql5730/conf/my.cnf --user=mysql &
4.继续报错
[root@localhost ~]# mysqldump --set-gtid-purged=OFF --tab=/tmp/data db_hxl -u root -pmysql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Got error: 1: Can't create/write to file '/tmp/data/flush_test.txt' (Errcode: 13 - Permission denied) when executing 'SELECT INTO OUTFILE'
修改目录权限给mysql用户
chown -R mysql:mysql /tmp/data
5.再次导出
[root@localhost ~]# mysqldump --set-gtid-purged=OFF --tab=/tmp/data db_hxl -u root -pmysql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@localhost data]# ls -al
total 24
drwxrwxr-x. 2 mysql mysql 176 Nov 9 18:22 .
drwxrwxrwt. 9 root root 172 Nov 9 18:18 ..
-rw-rw-r--. 1 root root 2468 Nov 9 18:22 flush_test.sql
-rw-rw-rw-. 1 mysql mysql 82 Nov 9 18:22 flush_test.txt
-rw-rw-r--. 1 root root 2738 Nov 9 18:22 rule_01.sql
-rw-rw-rw-. 1 mysql mysql 0 Nov 9 18:22 rule_01.txt
-rw-rw-r--. 1 root root 2485 Nov 9 18:22 tb_index_test.sql
-rw-rw-rw-. 1 mysql mysql 0 Nov 9 18:22 tb_index_test.txt
-rw-rw-r--. 1 root root 2342 Nov 9 18:22 tb_test.sql
-rw-rw-rw-. 1 mysql mysql 66 Nov 9 18:22 tb_test.txt
可以看到整个库下的表都导出了
文件说明:
*.sql --创建表的语句
*.txt --文件内容,格式如下
[root@localhost data]# more flush_test.txt
1 name1
2 name2
3 name3
4 name4
5 name5
6 name6
7 name7
8 name8
9 name9
10 name10
说明:
导出单个表
mysqldump --set-gtid-purged=OFF --tab=/tmp/data db_hxl flush_test -u root -pmysql
库名:db_hxl
表名:flush_test
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?