青蛙小白
#Mysql

使用MySQL的可传输表空间特性恢复表或迁移表数据

在MySQL运维中可能会遇到以下两个需求的场景,一个是从MySQL的备份中恢复单个表;另一个是将一套环境数据库某个表中的数据导入到另一套环境的数据中。 对于前者肯定需要用到数据库的备份,而对于后者如果使用普通的mysqldump导出表数据再导入的方式将十分缓慢。 MySQL从5.6开始支持了可传输表空间(Transportable Tablespaces)特性,该特性允许表空间(table.ibd)从一个实例拷贝到另一个实例上,使用这个特性可以实现前面提到的两个运维场景。

#Mysql

MySQL多源复制故障修复, 重新初始化一个channel的复制

MySQL 5.7数据库多源复制拓扑如下: M1 --------+ | | v M2 ------->S M1和M2为两个主数据库实例,S为从数据库实例,建立了从M1到S和从M2到S的多源复制。 S上执行: SHOW SLAVE STATUS \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: x.x.x.x Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000106 Read_Master_Log_Pos: 15847815 Relay_Log_File: relay-bin-m1.000003 Relay_Log_Pos: 15684092 Relay_Master_Log_File: binlog.000106 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: sys.%,performance_schema.%,mysql.%,information_schema.% Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 15847815 Relay_Log_Space: 15684290 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 86 Master_UUID: @17070e4d-a4bc-49b6-88d4-cbbc610abc2b Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: 134db0a3-61a4-4f96-8574-a3ec77045987:68811801-68821751 Executed_Gtid_Set: 30d1ce13-e8b0-43ae-b989-667aa0394fb8:1-240, f7123455-4085-4e24-a028-e0cff16d1cc6:1-8409014, f0c67103-9183-46c3-b34f-1b7fac7c0f51:1, 17070e4d-a4bc-49b6-88d4-cbbc610abc2b:1, bb09bbce-c153-4af2-ab6f-85e70b74a13c:1-3, cc96b6de-d317-4881-9a86-9c9b690cb8cc:1-15, 178dde0c-492c-4365-96e2-57008f2bd232:1-524521756, da0e0547-a1ca-4cae-8db9-f3a90b3a996a:1, 134db0a3-61a4-4f96-8574-a3ec77045987:1-68821751 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: m1 Master_TLS_Version: *************************** 2. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: x.x.x.x Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.002584 Read_Master_Log_Pos: 127954993 Relay_Log_File: relay-bin-m2.003944 Relay_Log_Pos: 127955152 Relay_Master_Log_File: binlog.002584 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: sys.%,performance_schema.%,mysql.%,information_schema.% Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 127954993 Relay_Log_Space: 127955430 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 69 Master_UUID: c8822a1d-d39c-11e9-8301-fa163e13923c Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: 178dde0c-492c-4365-96e2-57008f2bd232:524093802-524521756 Executed_Gtid_Set: 30d1ce13-e8b0-43ae-b989-667aa0394fb8:1-240, f7123455-4085-4e24-a028-e0cff16d1cc6:1-8409014, f0c67103-9183-46c3-b34f-1b7fac7c0f51:1, 17070e4d-a4bc-49b6-88d4-cbbc610abc2b:1, bb09bbce-c153-4af2-ab6f-85e70b74a13c:1-3, cc96b6de-d317-4881-9a86-9c9b690cb8cc:1-15, 178dde0c-492c-4365-96e2-57008f2bd232:1-524521756, da0e0547-a1ca-4cae-8db9-f3a90b3a996a:1, 134db0a3-61a4-4f96-8574-a3ec77045987:1-68821751 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: m2 Master_TLS_Version: 2 rows in set (0.00 sec) 多源复制(Multi-source replication)是指在一个数据库中从多个源数据库中复制数据到同一个目标数据库的过程。要在 MySQL 中实现多源复制,需要在目标数据库中创建多个复制通道(replication channel),每个通道对应一个源数据库。每个通道都需要有独立的复制配置,包括源数据库的连接信息、复制过滤规则等。

#Docker

配置和体验Docker Swarm

本当记录按照Docker官方swarm-tutoria文档,配置和体验Docker Swarm Mode的过程。 准备 主机: manager1 - 192.168.61.10, CentOS7 worker1 - 192.168.61.11, CentOS7 worker2 - 192.168.61.12, CentOS7 Docker Engine > 1.12 Get Docker for CentOS Docker 1.13安装 开放端口2377 tcp端口, 7946 4789 tcp udp 端口 初始化集群(manager node) 在manager1上执行docker swarm init --advertise-addr 192.168.61.10命令初始化集群: docker swarm init --advertise-addr 192.168.61.10 Swarm initialized: current node (jqcx4dbr1y00espou3mtmp6m3) is now a manager. To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-55deh9541886sn6qsnwa2xq62f0s8k5urdbje8sqerhmb0b33e-8cgailtk9yzt7am7gfjh64foc \ 192.168.61.10:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. 当前节点被切换成swarm模式,同时作为集群的manager节点。集群中的其他节点通过advertise-addr访问manager节点。使用docker info查看swarm状态:

#Go

Go 1.8的几个新特性

Go1.8发布了,这里先简单学习一下Go1.8的几个新特性。 新的切片排序Api 在以前要对切片排序要实现sort.Interface接口: package main import ( "fmt" "sort" ) type Person struct { Name string Age int } func (p Person) String() string { return fmt.Sprintf("%s: %d", p.Name, p.Age) } // ByAge implements sort.Interface for []Person based on // the Age field. type ByAge []Person func (a ByAge) Len() int { return len(a) } func (a ByAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age } func main() { people := []Person{ {"Bob", 31}, {"John", 42}, {"Michael", 17}, {"Jenny", 26}, } fmt.Println(people) sort.Sort(ByAge(people)) fmt.Println(people) } 现在只需这样做: