mysqldump --tab產生文字格式備份與mysql啟動選項--secure-file-priv的一點淵源
1,使用mysqldump --tab可以對資料庫產生文字檔案格式的備份
[root@mygirl ~]# /usr/local/mysql/bin/mysqldump --tab=/root test -u root -pEnter 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-priv180103 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 -pEnter 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 -pEnter 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 -pEnter 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 -pEnter 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 -pEnter 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
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `t_commit`
--
DROP TABLE IF EXISTS `t_commit`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_commit` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2018-01-03 21:31:42
[root@mygirl data]#
[root@mygirl data]# more t_commit.txt
1
2
3
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2149669/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 5.5 Slave節點備份指令碼(mysqldump)MySql指令碼
- mysql 邏輯備份 (mysqldump)MySql
- MySQL 5.5 mysqldump備份說明MySql
- mysql 備份資料庫 mysqldumpMySql資料庫
- 【MySQL】mysqldump備份失敗與解決方案合集MySql
- mysql的常用備份工具:mysqldump和mysqlhotcopyMySql
- MYSQL自動備份策略的選擇與實踐MySql
- MySQL主從配置及mysqldump備份MySql
- mysql5.6 mysqldump備份報錯MySql
- mysql備份恢復mysqldump面面觀MySql
- mysqldump使用方法(MySQL資料庫的備份與恢復)MySql資料庫
- MySQLDump的備份方法MySql
- Mysqldump的備份流程MySql
- mysqldump與innobackupex備份過程你知多少(一)MySql
- MySQLDump Windows 下TXT格式備份(帶分隔符)MySqlWindows
- mysqldump 選項MySql
- mysql之 mysqldump 備份恢復詳解MySql
- Mysql增量備份之Mysqldump& MylvmbackupMySqlLVM
- MySQL資料庫mysqldump命令備份異常的一個案例MySql資料庫
- 簡記MySQL的邏輯備份(mydumper+mysqldump)MySql
- mysqldump同步生產到生產資料MySql
- mysqldump備份指令碼一例MySql指令碼
- MySQL增量備份與恢復例項MySql
- 【mysqldump】mysqldump及備份恢復示例MySql
- Mysql備份系列(2)--mysqldump備份(全量+增量)方案操作記錄MySql
- Mysql備份和還原資料庫-mysqldumpMySql資料庫
- mysqldump來備份MYSQL資料庫(指令碼)MySql資料庫指令碼
- mysqldump備份技巧分享MySql
- mysqldump 備份指令碼MySql指令碼
- mysqldump備份指令碼MySql指令碼
- 邏輯備份--mysqldumpMySql
- mysql的冷備份與熱備份MySql
- 關於mysqldump備份非事務表的注意事項MySql
- rman備份產生等待事件事件
- 簡單的mysqldump備份(windows)MySqlWindows
- 使用Mysqldump備份和恢復MySQL資料庫MySql資料庫
- 使用mysqldump對mysql進行備份和恢復MySql
- mysqldump引數選項MySql