1.InnoDB and Online DDL

ALTER TABLE tbl_name ADD PRIMARY KEY (column), ALGORITHM=INPLACE, LOCK=NONE;

https://dev.mysql.com/doc/refman/8.0/en/innodb-online-ddl.html

2.TRUNCATE TABLE后可用空间的使用

在innodb_file_per_table=on的条件下,可用空间释放给了操作系统。而在innodb_file_per_table=OFF(system tablespace)或( general tablespaces)情况下,空间可以从新利用,没有物理释放。

https://dev.mysql.com/doc/refman/8.0/en/innodb-truncate-table-reclaim-space.html

3.复制状态查看

* 从库查看slave_master_info表:select * from mysql.slave_master_info; 
* 从库查看slave_relay_log_info表:select * from mysql.slave_relay_log_info; 
* 从库查看slave_worker_info表:select * from mysql.slave_worker_info; 
* 从库查看replication_applier_status_by_worker表:select * from performance_schema.replication_applier_status_by_worker; 
* 从库查看replication_connection_status表:select * from performance_schema.replication_connection_status;

 4.GTID Sets

来源于同一个Master Server的的GTID,可以构成一个集合:

3E11FA47-71CA-11E1-9E33-C80AA9429562:-

The above example represents the first through fifth transactions originating on the MySQL server whose server_uuidis 3E11FA47-71CA-11E1-9E33-C80AA9429562. Multiple single GTIDs or ranges of GTIDs originating from the same server can also be included in a single expression, with the GTIDs or ranges separated by colons, as in the following example:

3E11FA47-71CA-11E1-9E33-C80AA9429562:-::-

A GTID set can include any combination of single GTIDs and ranges of GTIDs, and it can include GTIDs originating from different servers. This example shows the GTID set stored in the gtid_executed system variable (@@GLOBAL.gtid_executed) of a slave that has applied transactions from more than one master:

2174B383--11E8-B90A-C80AA9429562:-, 24DA167-0C0C-11E8--00059A3C7B00:-

 5.gtid_executed table 

GTIDs are stored in the mysql.gtid_executed table only when gtid_mode is ON or ON_PERMISSIVE. Note that the mysql.gtid_executed table is cleared if you issue RESET MASTER.

Compression of the mysql.gtid_executed table is performed by a dedicated foreground thread namedthread/sql/compress_gtid_table.

SELECT * FROM performance_schema.threads WHERE NAME LIKE '%gtid%'\G

6.关于GTID复制模式的关联报错

If any of the transactions that should be sent by the master have been purged from the master's binary log, or added to the set of GTIDs in the gtid_purged system variable by another method, the master sends the errorER_MASTER_HAS_PURGED_REQUIRED_GTIDS to the slave, and replication does not start.  The GTIDs of the missing purged transactions are identified and listed in the master's error log in the warning message ER_FOUND_MISSING_GTIDS.

Attempting to reconnect without the MASTER_AUTO_POSITION option enabled only results in the loss of the purged transactions on the slave. The correct approach to recover from this situation is for the slave to replicate the missing transactions listed in the ER_FOUND_MISSING_GTIDS message from another source, or for the slave to be replaced by a new slave created from a more recent backup. Consider revising the binary log expiration period (binlog_expire_logs_seconds) on the master to ensure that the situation does not occur again.

If during the exchange of transactions it is found that the slave has received or committed transactions with the master's UUID in the GTID, but the master itself does not have a record of them, the master sends the errorER_SLAVE_HAS_MORE_GTIDS_THAN_MASTER to the slave and replication does not start. This situation can occur if a master that does not have sync_binlog=1 set experiences a power failure or operating system crash, and loses committed transactions that have not yet been synchronized to the binary log file, but have been received by the slave.

https://dev.mysql.com/doc/refman/8.0/en/replication-gtids-auto-positioning.html

7.复制的权限设置

Most of the steps that follow require the use of the MySQL root account or another MySQL user account that has theSUPER privilege. mysqladmin shutdown requires either the SUPER privilege or the SHUTDOWN privilege.

8.将MySQL 设置为read_only 

Make the servers read-only by setting the read_only system variable to ON on each server by issuing the following:

mysql> SET @@GLOBAL.read_only = ON;

这个命令的重要作用是:

Wait for all ongoing transactions to commit or roll back. Then, allow the slave to catch up with the master. It is extremely important that you make sure the slave has processed all updates before continuing.

9.shut down the MySQL

shell> mysqladmin -uusername -p shutdown

Then supply this user's password at the prompt.

https://dev.mysql.com/doc/refman/8.0/en/replication-gtids-howto.html

https://www.cnblogs.com/dadonggg/p/8625500.html

10.如何跳过一个GTID

基于GTID的复制,跳过一个事务,需要利用一个空事务来完成。

stop slave;

SET GTID_NEXT='aaa-bbb-ccc-ddd:N';

BEGIN;
COMMIT; SET GTID_NEXT='AUTOMATIC'; start slave;

https://dev.mysql.com/doc/refman/8.0/en/replication-gtids-failover.html

11.多源复制

In a multi-source replication topology, a slave creates a replication channel for each master that it should receive transactions from.

The error codes and messages that are issued when multi-source replication is enabled specify the channel that generated the error.

https://dev.mysql.com/doc/refman/8.0/en/replication-multi-source.html

 12.显示创建表的scripts

show create table student;

13 shell 操作mysql

关于salve节点的重新执行SQL的线程

mysql -e 'STOP SLAVE SQL_THREAD;'

14.mysqldump

Run mysqldump to dump your databases. You may either dump all databases or select databases to be dumped. For example, to dump all databases:

mysqldump --all-databases > fulldb.dump

备份数据库结构,不备份数据

格式:mysqldump -h主机名 -P端口 -u用户名 -p密码 --no-data 数据库名1 数据库名2 数据库名3 > 文件名.sql

mysqldump --no-data –databases db1 db2 cmdb > /data/backup/structure.sql

https://dev.mysql.com/doc/refman/8.0/en/replication-solutions-backups-mysqldump.html

https://baijiahao.baidu.com/s?id=1612955427840289665&wfr=spider&for=pc

15.基于既有表创建一个新表

  • create table as 只是复制原数据,其实就是把查询的结果建一个表
  • create table like 产生与源表相同的表结构,包括索引和主键,数据需要用insert into 语句复制进去。例如:
create table newtest like test;
insert into newtest select * from test;

 16.MHA FailOver

MHA 在线切换过程
https://blog.csdn.net/leshami/article/details/45189825

MHA 手动故障转移

https://blog.csdn.net/leshami/article/details/45219821

17.GTID模式下配置主从

change master to master_host='172.XXX.XXX.XXX',master_port=????,master_user='XXXX',master_password='XXXXXX',master_auto_position=1;
start slave;

 18.手动启动MHA Manager

nohup /usr/local/bin/masterha_manager --conf=/etc/mha/app1.cnf  --remove_dead_master_conf --ignore_last_failover < /dev/null > /data/log/mha/manager.log >& &

19.查看某数据库下所有表的具体信息(information_schema.TABLES

 SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'XXXXdb';

例如查看数据库中以winxin开头的各表的数据量

 SELECT table_name,table_rows FROM information_schema.tables WHERE TABLE_name like 'winxin%' ORDER BY  table_rows DESC;

20.生成批量修改表的SQL语句

例如:生成清空分库分表中的ABC开头某类表

SELECT CONCAT( 'truncate table ', table_name, ';' )
FROM information_schema.tables
WHERE table_name LIKE 'ABC_%' and table_name not LIKE 'terminal_user_%' ;

如果还要加上库名,例如删除某类表

SELECT CONCAT('drop table QQ_weixin_co.', table_name, ';')
FROM information_schema.tables
WHERE table_schema = 'QQ_weixin_co' AND table_name LIKE 'ABC_%'

21 Truncate 命令在 binlog中的记录形式

TRUNCATE TABLE is treated for purposes of binary logging and replication as DROP TABLE followed by CREATE TABLE—that is, as DDL rather than DML. This is due to the fact that, when using InnoDB and other transactional storage engines where the transaction isolation level does not permit statement-based logging (READ COMMITTED or READ UNCOMMITTED), the statement was not logged and replicated when using STATEMENT or MIXED logging mode. (Bug #36763) However, it is still applied on replication slaves using InnoDB in the manner described previously.

--https://dev.mysql.com/doc/refman/8.0/en/truncate-table.html

--个人学习笔记系列,可能比较粗糙,观者见谅。

MySQL 学习笔记 (一)的更多相关文章

  1. Mysql学习笔记(三)对表数据的增删改查。

    正文内容. 这一部分是最简单的,也是最麻烦的.简单是因为其实只包括增删该插四个部分.大体上看,增加数据.删除数据.修改数据.查询数据都不麻烦啊,我们日常都是常用的.这个谁不会呢?以前在培训机构学mys ...

  2. MySQL学习笔记一

    MySQL 学习笔记 一 一.数据库简单介绍 1. 按照数据库的发展时间顺序,主要出现了以下类型数据库系统: Ø 网状型数据库 Ø 层次型数据库 Ø 关系型数据库 Ø 面向对象数据库 上面4中数据库系 ...

  3. Mysql学习笔记(二)数据类型 补充

    原文:Mysql学习笔记(二)数据类型 补充 PS:简单的补充一下数据类型里的String类型以及列类型... 学习内容: 1.String类型 2.列类型存储需求 String类型: i.char与 ...

  4. Mysql学习笔记(一)数据类型

    原文:Mysql学习笔记(一)数据类型 学习内容: Mysql基本数据类型. 1.数字类型.. i.整型     Mysql数据类型             含义(有符号)     tinyint(m ...

  5. 初识mysql学习笔记

    使用VMVirtualBox导入Ubuntu后,可以通过sudo apt-get install mysql-server命令下载mysql. 在学习过程中,我遇到了连接不上Xshell的问题.最终在 ...

  6. MySQL学习笔记-锁相关话题

    在事务相关话题中,已经提到事务隔离性依靠锁机制实现的.在本篇中围绕着InnoDB与MyISAM锁机制的不同展开,进而描述锁的实现方式,多种锁的概念,以及死锁产生的原因.   Mysql常用存储引擎的锁 ...

  7. MySQL学习笔记-事务相关话题

    事务机制 事务(Transaction)是数据库区别于文件系统的重要特性之一.事务会把数据库从一种一致状态转换为另一个种一致状态.在数据库提交工作时,可以确保其要么所有修改都已经保存了,要么所有修改都 ...

  8. MySQL学习笔记-数据库文件

    数据库文件 MySQL主要文件类型有如下几种 参数文件:my.cnf--MySQL实例启动的时候在哪里可以找到数据库文件,并且指定某些初始化参数,这些参数定义了某种内存结构的大小等设置,还介绍了参数类 ...

  9. MySQL学习笔记-数据库内存

    数据库内存 InnoDB存储引擎内存由以下几个部分组成:缓冲池(buffer pool).重做日志缓冲池(redo log buffer)以及额外的内存池(additional memory pool ...

  10. MySQL学习笔记-数据库后台线程

    数据库后台线程 默认情况下讲述的InnoDB存储引擎,以后不再重复声明.后台线程有7个--4个IO thread,1个master thread,1个锁监控线程,1个错误监控线程.IO thread的 ...

随机推荐

  1. 结构体与typedef的使用,还有结构体指针的使用(二层结构体指针)

    该类容摘抄自以下链接,为学习之后的记录,不是鄙人原创. 学习链接:https://blog.csdn.net/a2013126370/article/details/78230890 typedef ...

  2. MySQL InnoDB 存储引擎原理浅析

    注:本文主要基于MySQL 5.6以后版本编写,多数知识来着书籍<MySQL技术内幕++InnoDB存储引擎>,本文章仅记录个人认为比较重要的部分,有兴趣的可以花点时间读原书. 一.MyS ...

  3. 使用iCamera 测试MT9F002 1400w高分辨率摄像头小结 之!!看清细节!!!

    使用iCamera 测试MT9F002 1400w高分辨率摄像头小结 之!!看清细节!!! 本方案测试两种种分辨率输出(其他更多分辨率设置,可以参考手册配置) 4608*3288=1515万像素 11 ...

  4. OS OSTEP (Operating Systems Three Easy pieces 操作系统导论 )

    读<OSTEP>的一点重点记录与感悟 (未完) Chapter-2 第二章 1. 操作系统的设计目标:  抽象.高性能.保护.不间断运行. 抽象:建立一些“抽象”,让操作系统方便和易于使用 ...

  5. C#写入(覆盖形式)数据到CSV文件 和 读取CSV文件

    /// <summary> /// 写入数据到CSV文件,覆盖形式 /// </summary> /// <param name="csvPath"& ...

  6. 基于WCF 的远程数据库服务访问技术

    原文出处:http://www.lw80.cn/shuji/jsjlw/13588Htm.Htm摘要:本文介绍了使用WCF 建立和运行面向服务(SOA)的数据库服务的系统结构和技术要素,分析了WCF ...

  7. 记录一次创建.net core 项目 并且发布到docekr【完全新手入门】

    1]环境说明 操作系统:Window 10 专业版 开发工具 Vs2019专业版 Docker:  Docker for Windows  2]创建.net core项目并且发布 2.0先打开并且运行 ...

  8. Django:永别了pycrypto库~

    在开发微信登陆功能时,解密用户信息需要使用到 Crypto 包,所以安装了pycrypto库. Linux.OS X 系统均可直接 pip install pycrypto . 最近换到win10下开 ...

  9. Android: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath':

    我按照ExoPlayer的github指引添加 implementation 'com.google.android.exoplayer:exoplayer:2.X.X' 发现根本run不起来,并报错 ...

  10. 面试连环炮系列(二):你们的项目Redis做了集群部署吗

    你们的项目Redis做了集群部署吗? 我们有大量数据需要缓存,而单实例的容量毕竟是有限的,于是做了Redis集群部署. 采取的方案是什么,Codis还是Redis Cluster,为什么要选择这个方案 ...