一、安装chameleon工具
1.下载源码
git clone git@gitee.com:opengauss/openGauss-tools-chameleon.git
2.创建Python虚拟环境并激活
安装依赖:
yum install mysql-devel gcc gcc-devel python-devel
python3 -m venv venv
source venv/bin/activate
3.进入代码的目录,执行python install命令安装
cd openGauss-tools-chameleon
python3 setup.py install
二、修改mysql端
1.mysql端创建用户usr_replica并授权
mysql -u root -p
创建数据库db_smis
创建用户并授权:
CREATE USER usr_replica IDENTIFIED BY 're@1qazx';
GRANT ALL ON db_smis.* TO 'usr_replica';
GRANT RELOAD ON *.* to 'usr_replica';
GRANT REPLICATION CLIENT ON *.* to 'usr_replica';
GRANT REPLICATION SLAVE ON *.* to 'usr_replica';
2.修改mysql配置文件my.cnf
mysqld节点加入如下内容:
[mysqld]
binlog_format = ROW
log_bin = mysql-bin
server_id = 1
binlog_row_image = FULL
gtid_mode = ON
enforce-gtid-consistency=on
3.重启mysql:systemctl restart mysql。
三、修改chameleon配置文件
1.切换用户smis,创建chameleon配置文件目录
su smis
chameleon set_configuration_files
cd /home/smis/.pg_chameleon/configuration/
复制一份默认的配置文件模板保存为default.yml:
cp config-example.yml default.yml
2.修改配置文件
vim default.yml,修改为如下内容:
---
# global settings
pid_dir: '~/.pg_chameleon/pid/'
log_dir: '~/.pg_chameleon/logs/'
log_dest: file
log_level: info
log_days_keep: 10
rollbar_key: ''
rollbar_env: ''
# type_override allows the user to override the default type conversion
# into a different one.
type_override:
"tinyint(1)":
override_to: boolean
override_tables:
- "*"
# postgres destination connection
pg_conn:
host: "192.168.132.153"
port: "5432"
user: "gaussdb"
password: "gaussdb@1qazx"
database: "db_smis"
charset: "utf8"
sources:
mysql:
readers: 4
writers: 4
db_conn:
host: "192.168.132.153"
port: "3306"
user: "usr_replica"
password: "re@1qazx"
charset: 'utf8'
connect_timeout: 10
schema_mappings:
db_smis: db_smis
limit_tables:
skip_tables:
grant_select_to:
- usr_readonly
lock_timeout: "120s"
my_server_id: 100
replica_batch_size: 10000
replay_max_rows: 10000
batch_retention: '1 day'
copy_max_memory: "300M"
copy_mode: 'file'
out_dir: /tmp
sleep_loop: 1
on_error_replay: continue
on_error_read: continue
auto_maintenance: "disabled"
gtid_enable: false
type: mysql
skip_events:
insert:
- delphis_mediterranea.foo # skips inserts on delphis_mediterranea.foo
delete:
- delphis_mediterranea # skips deletes on schema delphis_mediterranea
update:
keep_existing_schema: No
migrate_default_value: Yes
column_case_sensitive: Yes
mysql_restart_config: Yes
以上配置文件中参数的含义是:
迁移数据时,MySQL侧使用的用户名密码分别是 usr_replica 和 re@1qazx。MySQL服务器的IP和port分别是192.168.132.153和3306,待迁移的数据库是db_smis。
openGauss侧使用的用户名密码分别是 gaussdb和 gaussdb@1qazx。openGauss服务器的IP和port分别是192.168.132.153和5432,目标数据库是db_smis,同时会在db_smis下创建schema:db_smis,迁移的表都将位于该schema下。
3.初始化迁移过程
chameleon create_replica_schema --config default
chameleon add_source --config default --source mysql
4.复制基础数据。
chameleon init_replica --config default --source mysql --debug
debug参数可以查看执行过程。
5.schema db_smis已有数据