十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章主要讲解了“Mysql利用percona-xtrabackup在线配置主从的方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Mysql利用percona-xtrabackup在线配置主从的方法”吧!
创新互联建站专注于企业全网整合营销推广、网站重做改版、白城网站定制设计、自适应品牌网站建设、H5建站、商城系统网站开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为白城等各大城市提供网站开发制作服务。Mysql 利用percona-xtrabackup在线配置主从
一.在主从上分别安装Mysql
编译安装
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
groupadd mysql
useradd -g mysql mysql
mkdir -p /usr/local/mysql
[root@TESTDB02-1-16 tools]# tar -xf mysql-5.6.27.tar.gz
[root@TESTDB02-1-16 tools]# cd mysql-5.6.27
[root@TESTDB02-1-16 mysql-5.6.27]# pwd
/usr/local/tools/mysql-5.6.27
[root@TESTDB02-1-16 mysql-5.6.27]# mkdir -p /u02/mysql/data
[root@TESTDB02-1-16 mysql-5.6.27]# chown -R mysql:mysql /u02/mysql
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/u02/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make;
make install;
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
#prompt="(\u:HOSTNAME:)[\d]> "
prompt="\u@\h \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr
datadir = /u02/mysql/data
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 3072
back_log = 103
max_connections = 512
max_connect_errors = 100000
table_open_cache = 512
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 51
query_cache_size = 22M
#default_table_type = InnoDB
tmp_table_size = 96M
max_heap_table_size = 96M
slow_query_log = 1
slow_query_log_file = /u02/mysql/log/slow.log
log-error = /u02/mysql/log/error.log
long_query_time = 3
server-id = 77
log-bin = /u02/mysql/log_bin/log_bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1024M
expire_logs_days = 1
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
key_buffer_size = 15M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
transaction_isolation = REPEATABLE-READ
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 502M
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_locks_unsafe_for_binlog = 0
[mysqldump]
quick
max_allowed_packet = 32M
主库:
cd /usr/local/mysql/scripts
[root@ scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/u02/mysql/data/
cp ./support-files/mysql.server /etc/init.d/mysqld
主库修改密码
导入所需求库
mysql -uroot -p test
利用percona-xtrabackup备份库
主从安装percona-xtrabackup
wget /tupian/20230522/downloads --socket=/data/mysql/mysql.sock --parallel=8 --user=root --password=XMSSSS /data/backup/hotbackup
scp -r /data/backup/hotbackup/* root@备库:/u02/mysql/hotbackup
主库建帐户
GRANT REPLICATION SLAVE ON *.* TO '用户名'@'从库ip' IDENTIFIED BY '密码';
从库恢复
cd /u02/mysql/hotbackup
注意在从库恢复之前建好my.cnf,如果主库打开忽略大小写,从库也要一样,不然会报错
innobackupex --user=root --password=密码 --defaults-file=/etc/my.cnf --apply-log /u02/mysql/hotbackup/2015-10-28_17-30-50/
innobackupex --copy-back /u02/mysql/hotbackup/2015-10-28_17-30-50/
chown -R mysql:mysql /u02/mysql
service mysql start
cat xtrabackup_binlog_info
log_bin.000006 928891450
记住此logbin和pos
CHANGE MASTER TO MASTER_HOST='主IP', MASTER_USER='用户名', MASTER_PASSWORD='密码', MASTER_LOG_FILE='log_bin.000006', MASTER_LOG_POS=928891450;
start slave;
show slave status \G
感谢各位的阅读,以上就是“Mysql利用percona-xtrabackup在线配置主从的方法”的内容了,经过本文的学习后,相信大家对Mysql利用percona-xtrabackup在线配置主从的方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!