iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >mysqldump --tab产生文本格式备份与mysql启动选项--secure-file-priv的一点渊源
  • 422
分享到

mysqldump --tab产生文本格式备份与mysql启动选项--secure-file-priv的一点渊源

2024-04-02 19:04:59 422人浏览 独家记忆
摘要

1,使用Mysqldump --tab可以对数据库产生文本文件格式的备份 [root@mygirl ~]# /usr/local/mysql/bin/mysqldump --tab=/root tes

1,使用Mysqldump --tab可以对数据库产生文本文件格式的备份

[root@mygirl ~]# /usr/local/mysql/bin/mysqldump --tab=/root test -u root -p
Enter passWord
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@mygirl ~]# 


2,查看--secure-file-priv选项含义

[root@mygirl ~]# /usr/local/mysql/bin/mysqld --verbose --help|grep -i --color secure-file-priv
180103 20:45:01 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
180103 20:45:01 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.5.58) starting as process 4922 ...
180103 20:45:01 [Note] Plugin 'FEDERATED' is disabled.
  --secure-file-priv=name 
secure-file-priv                                  NULL
[root@mygirl ~]# 


3,关闭mysql server

[root@mygirl ~]# /usr/local/mysql/bin/mysqladmin shutdown -u root -p
Enter password: 


4,修正选项--secure-file-priv重启mysql server

[root@mygirl ~]# /usr/local/mysql/bin/mysqld_safe --secure-file-priv=/usr/local/mysql &
[1] 5335
[root@mygirl ~]# 180103 21:25:57 mysqld_safe Logging to '/usr/local/mysql/data/mygirl.err'.
180103 21:25:57 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data


5,看来选项修改的结果不合理,备份仍旧报错

[root@mygirl ~]# /usr/local/mysql/bin/mysqldump --tab=/root test -u root -p
Enter password: 
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@mygirl ~]# 


mysql> show variables like '%secure_file%';
+------------------+-------------------------------------------------+
| Variable_name    | Value                                           |
+------------------+-------------------------------------------------+
| secure_file_priv | /usr/local/mysql-5.5.58-linux-glibc2.12-x86_64/ |
+------------------+-------------------------------------------------+
1 row in set (0.00 sec)


6,再次关闭mysql server

[root@mygirl ~]# /usr/local/mysql/bin/mysqladmin shutdown -u root -p
Enter password: 
[root@mygirl ~]# 


7,再次修改--secure-file-priv,即配置为空,可以产生文本格式的备份

[root@mygirl ~]# /usr/local/mysql/bin/mysqld_safe --secure-file-priv=  &
[1] 5488
[root@mygirl ~]# 180103 21:30:23 mysqld_safe Logging to '/usr/local/mysql/data/mygirl.err'.
180103 21:30:23 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data


[root@mygirl ~]# 


+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_file_priv |       |
+------------------+-------+
1 row in set (0.00 sec)


8,--tab只能指定所有权为mysql用户及组的目录,否则报错

[root@mygirl ~]# /usr/local/mysql/bin/mysqldump --tab=/root test -u root -p
Enter password: 
mysqldump: Got error: 1: Can't create/write to file '/root/t_commit.txt' (Errcode: 13) when executing 'SELECT INTO OUTFILE'
[root@mygirl ~]# 


9,文本格式的备份在--tab指定的目录,并且数据库中每个表皆有2个不同扩展名的文件,各为.sql and .txt

[root@mygirl ~]# /usr/local/mysql/bin/mysqldump --tab=/usr/local/mysql/data test -u root -p
Enter password: 
[root@mygirl ~]# 


[root@mygirl ~]# ll /usr/local/mysql/data/t_*
-rw-r--r--. 1 root  root  1311 Jan  3 21:31 /usr/local/mysql/data/t_commit.sql
-rw-rw-rw-. 1 mysql mysql    6 Jan  3 21:31 /usr/local/mysql/data/t_commit.txt
-rw-r--r--. 1 root  root  1308 Jan  3 21:31 /usr/local/mysql/data/t_other.sql
-rw-rw-rw-. 1 mysql mysql    0 Jan  3 21:31 /usr/local/mysql/data/t_other.txt


10,可见上述.sql和.txt文件分别对应每个表的定义表的脚本及表的实质数据

[root@mygirl ~]# cd  /usr/local/mysql/data
[root@mygirl data]# more t_commit.sql
-- MySQL dump 10.13  Distrib 5.5.58, for linux-glibc2.12 (x86_64)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version       5.5.58


;
;
;
;
;
;
;
;


--
-- Table structure for table `t_commit`
--


DROP TABLE IF EXISTS `t_commit`;
;
;
CREATE TABLE `t_commit` (
  `a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
;


;


;
;
;
;
;


-- Dump completed on 2018-01-03 21:31:42
[root@mygirl data]# 




[root@mygirl data]# more t_commit.txt
1
2
3




您可能感兴趣的文档:

--结束END--

本文标题: mysqldump --tab产生文本格式备份与mysql启动选项--secure-file-priv的一点渊源

本文链接: https://www.lsjlt.com/news/49929.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作