MySQL
dbbot provides deployment, backup and common operations playbooks for the MySQL ecosystem. This page is used to explain the applicable scenarios, core variables and execution entry points of each script.
Preparation before execution
Before executing any MySQL Playbook, it is recommended to complete the following preparations:
- Refer to Deploy dbbot and configure Ansible to complete the control node preparation.
- Refer to dbbot Configuration and Single-Node Deployment Demo to configure
inventory/hosts.iniandcommon_config.yml. - Perform a connectivity check in the
playbooks/directory:ansible dbbot_mysql -m ping.
1. Deploy a Single Node
For a complete example of standalone deployment, see: dbbot Configuration and Single-Node Deployment Demo.
ansible-playbook single_node.yml
2. Deploy Primary-Replica Topology
For a complete example of one primary and two replicas, see: MySQL Deployment Quick Start.
| Parameter value | Type | Explanation |
|---|---|---|
master_ip | String | Master IP address |
replica_ips | String list | Replica IP address list |
sub_nets | String | MySQL trusted network segment, trusted domain or trusted IP |
ansible-playbook master_slave.yml
3. Deploy MHA
For MHA support scope and variable descriptions, see: MySQL MHA Deployment Guide.
| Parameter value | Type | Explanation |
|---|---|---|
master_ip | String | Master IP address |
replica_ips | String list | Replica IP address list |
sub_nets | String | MySQL trusted network segment, trusted domain or trusted IP |
manager_ip | String | The node where the MHA manager is located, cannot be the same as master_ip |
net_work_interface | String | The name of the network card bound to the VIP |
vip | string | VIP address |
vip_netmask | String | VIP netmask, common value is 32 |
ansible-playbook mha.yml
dbbot supports both traditional three-machine MHA and dual-machine MHA.
4. Deploy MGR
| Parameter value | Type | Explanation |
|---|---|---|
mysql_binlog_format | String | MGR must use row, this variable is used to override the common configuration |
mysql_mgr_hosts | String list | MGR member IP list, by default the first IP is set to primary |
sub_nets | String | MySQL trusted network segment, trusted domain or trusted IP |
greatsql_vip | String | VIP of GreatSQL HA, only valid in GreatSQL HA scenario |
greatsql_net_work_interface | String | The network card name of GreatSQL HA bound VIP |
greatsql_netmask | String | The netmask used by GreatSQL HA, the common value is 32 |
greatsql_group_replication_arbitrator | Boolean | Whether to enable the arbitration node |
greatsql_group_replication_arbitrator_hosts | String list | Arbitrator node list |
ansible-playbook mgr.yml
Description:
- The deployment result defaults to single-master mode.
mgr.ymlcurrently supports MySQL8.0.xand8.4.x.- When
mgr_use_random_uuid: 1is set, the 8.0 and 8.4 templates will automatically generate and deliver a newgroup_replication_group_name. - Multi-master mode is not recommended as the default deployment mode. If necessary, please switch manually after validation.
5. Deploy InnoDB Cluster
For the full InnoDB Cluster guide, see: MySQL InnoDB Cluster Deployment Guide.
ansible-playbook innodb_cluster.yml
6. Deploy xtrabackup
install_xtrabackup.yml is only for MySQL 5.7 physical backup.
ansible-playbook install_xtrabackup.yml
Description:
- dbbot selects built-in RPMs based on the target operating system.
- EL7 class systems use
percona-xtrabackup-24-2.4.26-1.el7.x86_64.rpm. - EL8 class systems use
percona-xtrabackup-24-2.4.28-1.el8.x86_64.rpm.
7. Deploy mysqlshell
ansible-playbook install_mysqlshell.yml
Suggestions:
- Prioritize deployment of
8.0+mysqlshell. - The mysqlshell version is backward compatible and can be used to manage MySQL 5.7.
8. Uninstall MySQL
ansible-playbook unsafe_uninstall.yml
unsafe_uninstall.yml will only delete the data directory, log directory and systemd service of the target instance, but will not clean up the entire software base directory.
9. Deploy the 5.7 Backup Script
ansible-playbook backup_script.yml
Description:
- Only supports MySQL
5.7. - The script will perform both xtrabackup installation and backup script deployment.
- The backup script is generated by default in
{{ mysql_data_dir_base }}/backup{{ mysql_port }}.sh. - Scheduled tasks are written to the
mysqluser crontab, but not to/etc/cron.d/. - Default cron is
02:00every day. - Supports physical full backup, binlog archiving,
my.cnfarchiving and simple retention policy. - It is recommended to use the
mysqluser when executing manually, for examplesu - mysql -c "sh /database/mysql/backup3310.sh".
10. MySQL 8.4 Backup and Restore
MySQL 8.4 uses a clone-based backup and PITR restore workflow. For details, see: MySQL 8.4 Backup and Restore.
Related playbooks:
ansible-playbook backup_script_8.4.ymlansible-playbook restore_pitr_8.4.yml
11. Deploy keepalived + Primary-Replica
keepalived_master_slave.yml is currently not recommended for production use. It should not be used as a recommended architecture for official releases.
12. Login
su - mysql
db3306