c如何实现数据库同步(oracle数据同步日志)

1、mysql master1部署

安装依赖包

yum install -y yum-utils

配置yum源

vi /etc/yum.repos.d/mysql.repo

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

查看可安装c如何实现数据库同步的mysql版本:

yum repolist all|grep mysql

yum安装mysql

yum install mysql-community-server -y

启动mysql服务

systemctl start mysqld

systemctl status mysqld

systemctl enable mysqld

root账户默认密码存储在错误日志中:

# grep 'temporary password' /var/log/mysqld.log

# mysql -uroot -p

mysql> set global validate_password_length=4;

mysql> set global validate_password_policy=0;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';

修改mysql配置文件

[client]

port = 3306

default-character-set = utf8mb4

[mysql]

port = 3306

default-character-set = utf8mb4

[mysqld]

user = mysql

port = 3306

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

bind-address = 0.0.0.0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

server-id = 113

log-bin = mysql-bin

auto-increment-increment = 2

auto-increment-offset = 1

sync_binlog = 1

slave-skip-errors = all

interactive_timeout = 57600

expire_logs_days = 7

max_connections = 10240

open_files_limit = 65535

innodb_buffer_pool_size = 1G

innodb_flush_log_at_trx_commit = 2

innodb_log_file_size = 256M

binlog-ignore-db = mysql #不需要同步的数据库

binlog_ignore_db = information_schema

binlog_ignore_db = performation_schema

binlog_ignore_db = sys

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

[mysqldump]

quick

quote-names

max_allowed_packet = 16M

重启mysql服务

systemctl restart mysqld

登陆mysql

mysql -uroot -p'123456'

2、mysql master2安装

安装依赖包

yum install -y yum-utils

配置yum源

vi /etc/yum.repos.d/mysql.repo

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

查看可安装的mysql版本:

yum repolist all|grep mysql

yum安装mysql

yum install mysql-community-server -y

启动mysql服务

systemctl start mysqld

systemctl status mysqld

systemctl enable mysqld

root账户默认密码存储在错误日志中:

# grep 'temporary password' /var/log/mysqld.log

# mysql -uroot -p

mysql> set global validate_password_length=4;

mysql> set global validate_password_policy=0;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';

修改mysql配置文件

[client]

port = 3306

default-character-set = utf8mb4

[mysql]

port = 3306

default-character-set = utf8mb4

[mysqld]

user = mysql

port = 3306

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

bind-address = 0.0.0.0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

server-id = 114

log-bin = mysql-bin

auto-increment-increment = 2

auto-increment-offset = 2

sync_binlog = 1

slave-skip-errors = all

interactive_timeout = 57600

expire_logs_days = 7

max_connections = 10240

open_files_limit = 65535

innodb_buffer_pool_size = 1G

innodb_flush_log_at_trx_commit = 2

innodb_log_file_size = 256M

binlog-ignore-db = mysql #不需要同步的数据库

binlog_ignore_db = information_schema

binlog_ignore_db = performation_schema

binlog_ignore_db = sys

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

[mysqldump]

quick

quote-names

max_allowed_packet = 16M

重启mysql服务

systemctl restart mysqld

登陆mysql

mysql -uroot -p'123456'

3、主主复制配置3.1、备份数据并导入数据

mysql -uroot -p'123456' -e "show databases"|grep -Ev "Database|mysql|information_schema|performance_schema|sys"|xargs mysqldump -uroot -p'123456' --databases > mysql_bak.sql

source /root/mysql_bak.sql;

3.2、数据同步

master2操作:

show master status;

master1操作:

mysql> stop slave;

mysql> change master to

master_host='192.168.1.114',

master_user='root',

master_password='123456',

master_log_file='mysql-bin.000001',

master_log_pos=90314628;

mysql> start slave;

mysql> show slave status\G;

master1操作:

show master status;

master2操作:

mysql> stop slave;

mysql> change master to

master_host='192.168.1.113',

master_user='root',

master_password='123456',

master_log_file='mysql-bin.000004',

master_log_pos=90314628;

mysql> start slave;

mysql> show slave status\G;

如果您喜欢本文c如何实现数据库同步,就请动动您的发财手为本文点赞评论转发,让c如何实现数据库同步我们一起学习更多运维相关知识,最后请记得关注我。

c如何实现数据库同步

发布于 2024-05-27 13:05:53
收藏
分享
海报
0 条评论
80
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~