MySQL Binlog日志查看&登录密码特殊字符转义

查看是否开启binlog

show variables like ‘%log_bin%’;

查看MySQL的数据存储目录

show variables like ‘%datadir%’;

登录MySQL,密码带特殊字符时使用“\”转义

/usr/local/mysql/bin/mysql -d -uroot -p!Admin@2021 -h 127.0.0.1 -P3306 mysql

MySQL导出数据库(mysql)的表结构

/usr/local/mysql/bin/mysqldump -d -uroot -p!Admin@2021 -h 127.0.0.1 -P3306 mysql > ~/mysql-$(date +%F)-all.sql

MySQL查看mysql的binlog记录并过滤出(system_)的记录,打印记录和紧跟的25行

/usr/local/mysql/bin/mysqlbinlog --no-defaults -v -d mysql /data/mysql/dbdata/binlog/mysql-bin.000007 | grep -A 25 system_ > ~/mysqlbinlog-$(date +%F)-7.txt

MySQL查看时间段(2020-12-01 00:00:00~2020-12-17 17:00:00)的binlog,并打印到文件

/usr/local/mysql/bin/mysqlbinlog --no-defaults -d mysql --start-datetime=“2020-12-01 00:00:00” --stop-datetime=“2020-12-17 17:00:00” /data/mysql/dbdata/binlog/mysql-bin.000007 > ~/mysql-mysqlbinlog-$(date +%F).txt

MySQL恢复binlog的区间(1000~2000)的记录到数据库[未尝试]

/usr/local/mysql/bin/mysqlbinlog --no-defaults -d mysql --start-position=“1000” --stop-position=“2000” /data/mysql/dbdata/binlog/mysql-bin.000007 | /usr/local/mysql/bin/mysql -uroot -pAgree@2021 -h 127.0.0.1 -P3306 mysql

MySQL将binlog的区间(1000~2000)的记录打印成“伪”SQL

/usr/local/mysql/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -v -d mysql --start-position=1000 --stop-position=2000 /data/mysql/dbdata/binlog/mysql-bin.000007 > ~/mysql-mysqlbinlog-$(date +%F).txt

你可能感兴趣的:(笔记,#,MySQL,mysql,数据库,sql)