首页 > 数据库 >mysqldump之where用法

mysqldump之where用法

时间:2023-10-21 13:32:28浏览次数:37  
标签:SET OLD -- rocksdb 用法 mysqldump mysql staffs where

文档课题:mysqldump之where用法.
数据库:MySQL 5.7.21
应用场景:实际生产中,需要运用mysqldump导出指定条件的数据,并且以insert语句的形式呈现,如下为相关测试.
1、数据库信息
mysql> select * from staffs;
+----+------+-----+---------+---------------------+
| id | name | age | pos     | add_time            |
+----+------+-----+---------+---------------------+
|  1 | z3   |  22 | manager | 2023-08-27 13:41:41 |
|  2 | July |  23 | dev     | 2023-08-27 13:41:41 |
|  3 | 2000 |  23 | dev     | 2023-08-27 13:41:42 |
+----+------+-----+---------+---------------------+
3 rows in set (0.00 sec)

mysql> desc staffs;
+----------+-------------+------+-----+-------------------+----------------+
| Field    | Type        | Null | Key | Default           | Extra          |
+----------+-------------+------+-----+-------------------+----------------+
| id       | int(11)     | NO   | PRI | NULL              | auto_increment |
| name     | varchar(24) | NO   | MUL |                   |                |
| age      | int(11)     | NO   |     | 0                 |                |
| pos      | varchar(20) | NO   |     |                   |                |
| add_time | timestamp   | NO   |     | CURRENT_TIMESTAMP |                |
+----------+-------------+------+-----+-------------------+----------------+
5 rows in set (0.00 sec)

mysql> select database();
+------------+
| database() |
+------------+
| booksDB    |
+------------+
1 row in set (0.00 sec)

2、相关测试
2.1、int字段测试
[mysql@mysql-leo-master ~]$ mysqldump -uroot -p --single-transaction --complete-insert --where='id=2' booksDB staffs > /home/mysql/staffs.txt             
Enter password: 
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. 

2.2、数据确认
[mysql@mysql-leo-master ~]$ ls -ltr
total 2216
-rw-rw-r--. 1 mysql mysql 2184442 Sep  2 14:30 full_backup.sql
drwxrwxr-x. 2 mysql mysql      38 Sep 23 17:40 etc
-rw-rw-r--. 1 mysql mysql    1277 Oct 15 10:54 20231015.log
-rw-rw-r--. 1 mysql mysql    3354 Oct 21 10:49 20231021.txt
-rw-rw-r--. 1 mysql mysql   67518 Oct 21 10:57 prd_catalog.txt
-rw-rw-r--. 1 mysql mysql    3582 Oct 21 12:59 staffs.txt
[mysql@mysql-leo-master ~]$ cat staffs.txt
-- MySQL dump 10.13  Distrib 5.7.21-20, for Linux (x86_64)
--
-- Host: localhost    Database: booksDB
-- ------------------------------------------------------
-- Server version       5.7.21-20-log

/*!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' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*!50717 SELECT COUNT(*) INTO @rocksdb_has_p_s_session_variables FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'performance_schema' AND TABLE_NAME = 'session_variables' */;
/*!50717 SET @rocksdb_get_is_supported = IF (@rocksdb_has_p_s_session_variables, 'SELECT COUNT(*) INTO @rocksdb_is_supported FROM performance_schema.session_variables WHERE VARIABLE_NAME=\'rocksdb_bulk_load\'', 'SELECT 0') */;
/*!50717 PREPARE s FROM @rocksdb_get_is_supported */;
/*!50717 EXECUTE s */;
/*!50717 DEALLOCATE PREPARE s */;
/*!50717 SET @rocksdb_enable_bulk_load = IF (@rocksdb_is_supported, 'SET SESSION rocksdb_bulk_load = 1', 'SET @rocksdb_dummy_bulk_load = 0') */;
/*!50717 PREPARE s FROM @rocksdb_enable_bulk_load */;
/*!50717 EXECUTE s */;
/*!50717 DEALLOCATE PREPARE s */;
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='d0dddbd8-43bd-11ee-ac2f-000c29763af3:1-1597530';

--
-- Table structure for table `staffs`
--

DROP TABLE IF EXISTS `staffs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `staffs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(24) NOT NULL DEFAULT '' COMMENT '姓名',
  `age` int(11) NOT NULL DEFAULT '0' COMMENT '年龄',
  `pos` varchar(20) NOT NULL DEFAULT '' COMMENT '职位',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入职时间',
  PRIMARY KEY (`id`),
  KEY `index_staffs_nameAgePos` (`name`,`age`,`pos`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='员工记录表';
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `staffs`
--
-- WHERE:  id=2

LOCK TABLES `staffs` WRITE;
/*!40000 ALTER TABLE `staffs` DISABLE KEYS */;
INSERT INTO `staffs` (`id`, `name`, `age`, `pos`, `add_time`) VALUES (2,'July',23,'dev','2023-08-27 05:41:41');
/*!40000 ALTER TABLE `staffs` ENABLE KEYS */;
UNLOCK TABLES;
SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;
/*!50112 SET @disable_bulk_load = IF (@is_rocksdb_supported, 'SET SESSION rocksdb_bulk_load = @old_rocksdb_bulk_load', 'SET @dummy_rocksdb_bulk_load = 0') */;
/*!50112 PREPARE s FROM @disable_bulk_load */;
/*!50112 EXECUTE s */;
/*!50112 DEALLOCATE PREPARE s */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!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 2023-10-21 12:59:45

2.3、varchar字段测试
[mysql@mysql-leo-master ~]$ mysqldump -uroot -p --single-transaction --complete-insert --where='name="July"' booksDB staffs > /home/mysql/staffs.txt
Enter password: 
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. 

2.4、数据确认
[mysql@mysql-leo-master ~]$ cat staffs.txt 
-- MySQL dump 10.13  Distrib 5.7.21-20, for Linux (x86_64)
--
-- Host: localhost    Database: booksDB
-- ------------------------------------------------------
-- Server version       5.7.21-20-log

/*!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' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*!50717 SELECT COUNT(*) INTO @rocksdb_has_p_s_session_variables FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'performance_schema' AND TABLE_NAME = 'session_variables' */;
/*!50717 SET @rocksdb_get_is_supported = IF (@rocksdb_has_p_s_session_variables, 'SELECT COUNT(*) INTO @rocksdb_is_supported FROM performance_schema.session_variables WHERE VARIABLE_NAME=\'rocksdb_bulk_load\'', 'SELECT 0') */;
/*!50717 PREPARE s FROM @rocksdb_get_is_supported */;
/*!50717 EXECUTE s */;
/*!50717 DEALLOCATE PREPARE s */;
/*!50717 SET @rocksdb_enable_bulk_load = IF (@rocksdb_is_supported, 'SET SESSION rocksdb_bulk_load = 1', 'SET @rocksdb_dummy_bulk_load = 0') */;
/*!50717 PREPARE s FROM @rocksdb_enable_bulk_load */;
/*!50717 EXECUTE s */;
/*!50717 DEALLOCATE PREPARE s */;
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='d0dddbd8-43bd-11ee-ac2f-000c29763af3:1-1597530';

--
-- Table structure for table `staffs`
--

DROP TABLE IF EXISTS `staffs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `staffs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(24) NOT NULL DEFAULT '' COMMENT '姓名',
  `age` int(11) NOT NULL DEFAULT '0' COMMENT '年龄',
  `pos` varchar(20) NOT NULL DEFAULT '' COMMENT '职位',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入职时间',
  PRIMARY KEY (`id`),
  KEY `index_staffs_nameAgePos` (`name`,`age`,`pos`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='员工记录表';
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `staffs`
--
-- WHERE:  name="July"

LOCK TABLES `staffs` WRITE;
/*!40000 ALTER TABLE `staffs` DISABLE KEYS */;
INSERT INTO `staffs` (`id`, `name`, `age`, `pos`, `add_time`) VALUES (2,'July',23,'dev','2023-08-27 05:41:41');
/*!40000 ALTER TABLE `staffs` ENABLE KEYS */;
UNLOCK TABLES;
SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;
/*!50112 SET @disable_bulk_load = IF (@is_rocksdb_supported, 'SET SESSION rocksdb_bulk_load = @old_rocksdb_bulk_load', 'SET @dummy_rocksdb_bulk_load = 0') */;
/*!50112 PREPARE s FROM @disable_bulk_load */;
/*!50112 EXECUTE s */;
/*!50112 DEALLOCATE PREPARE s */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!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 2023-10-21 13:05:14

说明:如上所示,指定条件的数据均成功以insert语句导出.

标签:SET,OLD,--,rocksdb,用法,mysqldump,mysql,staffs,where
From: https://blog.51cto.com/u_12991611/7966650

相关文章

  • Object.defineProperty用法
    1、能干啥?Object.defineProperty()可以给传入的对象动态的添加或修改属性2、怎么玩?Object.defineProperty(obj,prop,desc)它有三个参数:obj:需要定义属性的当前对象prop:当前需要定义的属性名;注意是string类型desc:属性描述符;注意是object类型desc常用的属性:value:......
  • 统计学Pearson,Kendall和Spearman 用法及公式。
    假设存在X1,X2,X3,…,Xn.n组对比参数,则有以下信息: I:KL散度、JS散度以及交叉熵对比1) Kl-div(KL散度):1、简介KL散度(Kullback–Leiblerdivergence)又称KL距离,相对熵。(数值归一化处理)当P(x)和Q(x)的相似度越高,KL散度越小。KL散度主要有两个性质:(1)不对称性尽管KL散......
  • MySQL CASE()用法
    MySQL中的CASE表达式用于根据条件进行条件判断和返回多个可能的值。它允许在查询中执行简单的逻辑判断,并根据不同的条件返回不同的值或执行不同的操作。CASE表达式有两种形式:简单CASE和搜索CASE。简单CASE形式:CASEexpressionWHENvalue1THENresult1WHE......
  • MySQL IF()用法
    MySQL中的IF函数用于根据条件返回两个值中的一个。它可以应用于复杂查询和更新语句中,以便根据条件动态生成值。IF函数的语法如下:IF(condition,value_if_true,value_if_false)其中,condition是一个布尔表达式或一个返回布尔值的函数,value_if_true是条件为TRUE时返回......
  • Mysql FIND_IN_SET()用法
    MySQL中的FIND_IN_SET函数用于在逗号分隔的字符串列表中查找指定字符串的位置。它接受两个参数:要查找的字符串和逗号分隔的字符串列表。语法如下:FIND_IN_SET(string,string_list)其中,string是要查找的字符串,string_list是逗号分隔的字符串列表。返回值为待查找字符串......
  • 什么是线程池,线程池的状态,线程池的用法示例
    线程池(ThreadPool)是一种用于管理和重复使用线程的并发编程机制。它是一种有效的方式来管理线程的生命周期、控制并发任务的执行,以及减少线程创建和销毁的开销。线程池在多线程应用程序中被广泛使用,因为它可以提高性能、资源利用率和响应速度。线程池通常包含以下主要组件:工作......
  • Go笔记(1)-变量的详细用法
    变量(1)变量的定义Go语言是静态类型的语言,所有类型都需要明确的定义。var是声明变量的关键字使用格式:var变量名变量类型变量命名规范:遵循驼峰格式,首个单词小写,每个新单词的首字母大写varnameString="WY"//var创建String类型的变量namename="JB"......
  • 求平均工资大于2500的部门平均工资是 having 新面孔比where强大的地方就在于它可以跟
       ---------------------------- ......
  • makefile中.PHNOY的用法
    makefile中PHONY的重要性     伪目标是这样一个目标:它不代表一个真正的文件名,在执行make时可以指定这个目标来执行所在规则定义的命令,有时也可以将一个伪目标称为标签。伪目标通过  PHONY来指明。   PHONY定义伪目标的命令一定会被执行,下面尝试分析这种优点的......
  • postgresql【JSONB用法】
    //userNametypecode是我拿到数据结构出来的可以写固定值来测试;code字段为上面设置的唯一约束。如果code值没有变就是修改,否则就是新增INSERTINTO表名(username,type,code)VALUES('${userName}','${type}','${code}')ONCONFLICT9.6语法支持(code)DOUPDATE......