Mysql共享锁
死锁问题 共享间隙锁引起的死锁 如何产生共享间隙锁 何时产生的隐式锁转换问题现象在一个事务内只会锁一行的数据,没有锁多行数据才会出现的顺序问题,但是会偶尔报个Deadlock事务内sql执行顺序...
2024.11.14备注:
在实际操作中如果不慎操作了错误的DML语句,如何快速的恢复,利用flashback可以对BINLOG的DML进行反向的解析,下面介绍如何安装及使用
1.安装git,因为要从github上面下载
yum install git
2.下载并安装
git clone https://github.com/Meituan-Dianping/MyFlash.git
yum install libgnomeui-devel -y #安装glib
cd MyFlash/
cat build.sh
sh build.sh
3.查看帮助
[root@db192168084125 MyFlash]# cd binary/
[root@db192168084125 binary]# ./flashback --help
Usage:
flashback [OPTION?]
Help Options:
-h, --help Show help options
Application Options:
--databaseNames databaseName to apply. if multiple, seperate by comma(,)
--tableNames tableName to apply. if multiple, seperate by comma(,)
--start-position start position
--stop-position stop position
--start-datetime start time (format %Y-%m-%d %H:%M:%S)
--stop-datetime stop time (format %Y-%m-%d %H:%M:%S)
--sqlTypes sql type to filter . support insert, update ,delete. if multiple, seperate by comma(,)
--maxSplitSize max file size after split, the uint is M
--binlogFileNames binlog files to process. if multiple, seperate by comma(,)
--outBinlogFileNameBase output binlog file name base
--logLevel log level, available option is debug,warning,error
--include-gtids gtids to process
--exclude-gtids gtids to skip
4.测试
插入数据
[root@localhost][test]> flush logs;
Query OK, 0 rows affected (0.04 sec)
[root@localhost][test]> show master status;
+---------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------+
| mysql-binlog.000004 | 194 | | | 99d89b20-c969-11e9-a27c-000c29924f35:1-8,
af7883dc-c43b-11e9-b42f-000c29924f35:1-5358804 |
+---------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
[root@localhost][test]> use test;
Database changed
[root@localhost][test]> insert into b select 1,‘a‘;
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
将binlog导出
[root@db192168084125 binary]# ./flashback --binlogFileNames=/usr/local/mysql/data/mysql-binlog.000004 --outBinlogFileNameBase=insert
[root@db192168084125 binary]# ll
总用量 7348
-rwxr-xr-x. 1 root root 82192 8月 29 00:12 flashback
-rw-r--r--. 1 root root 243 8月 29 01:15 insert.flashback
-rwxr-xr-x. 1 root root 7463125 8月 29 00:08 mysqlbinlog20160408
用mysqlbinlog查看,可以查看刚才的insert语句变成的delete语句
[root@db192168084125 bin]# ./mysqlbinlog -vv /software/MyFlash/binary/insert.flashback
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
delimiter /*!*/;
# at 4
#190829 1:13:48 server id 1 end_log_pos 123 CRC32 0xdc5e3b2e Start: binlog v 4, server v 5.7.26-log created 190829 1:13:48
# Warning: this binlog is either in use or was not closed properly.
BINLOG ‘
TLZmXQ8BAAAAdwAAAHsAAAABAAQANS43LjI2LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AS47Xtw=
‘/*!*/;
# at 123
#190829 1:14:13 server id 1 end_log_pos 170 CRC32 0xae1a43b0 Table_map: `test`.`b` mapped to number 229
# at 170
#190829 1:14:13 server id 1 end_log_pos 212 CRC32 0xd2057157 Delete_rows: table id 229 flags: STMT_END_F
BINLOG ‘
ZbZmXRMBAAAALwAAAKoAAAAAAOUAAAAAAAEABHRlc3QAAWIAAgMPAsgAA7BDGq4=
ZbZmXSABAAAAKgAAANQAAAAAAOUAAAAAAAEAAgAC//wBAAAAAWFXcQXS
‘/*!*/;
### delete FROM `test`.`b`
### WHERE
### @1=1 /* INT meta=0 nullable=1 is_null=0 */
### @2=‘a‘ /* VARSTRING(200) meta=200 nullable=1 is_null=0 */
# at 212
#190829 1:14:13 server id 1 end_log_pos 243 CRC32 0x32a640bb Xid = 223
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= ‘AUTOMATIC‘ /* added by mysqlbinlog */ /*!*/;
delimiter ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
回滚
./mysqlbinlog --skip-gtids -vv /software/MyFlash/binary/insert.flashback |mysql -uroot -p
[root@db192168084125 bin]# ./mysqlbinlog --skip-gtids -vv /software/MyFlash/binary/insert.flashback |mysql -uroot -p
Enter password:
死锁问题 共享间隙锁引起的死锁 如何产生共享间隙锁 何时产生的隐式锁转换问题现象在一个事务内只会锁一行的数据,没有锁多行数据才会出现的顺序问题,但是会偶尔报个Deadlock事务内sql执行顺序...
2024.11.14grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘password‘;flush privileges;执行后就可以了。常用的外网工具。
2024.11.15在使用mysql的时候我们经常需要用到排序方法,也就是order by,如果是数字类型的字段,我们一般用order by 或者order by desc就能解决, 但是,如果我们要对字符类型的数据进行...
2024.11.15数据准备select count(*) from account;800万数据.批量修改数据条数1000 条1,首先测试批量update set where id =? 性能:2、update acc...
2024.11.15概述今天介绍下mysql视图方面的内容,通俗的讲,视图就是一条select语句执行后返回的结果集。所以我们在创建视图的时候,主要的工作就落在创建这条SQL查询语句上。01特性视图是对若干张基本表的引用...
2024.11.15