DATAX 使用记录
批量表迁移
准备表
vim mysqltables.txt
tb_consultation_type
tb_conversation_record
tb_relation_record_consultation
tb_relation_student_group
tb_relation_teacher_college
tb_relation_teacher_consultation
tb_student_group
tb_student_info
tb_teacher_info
tb_teacher_time
tb_template_file
准备datax .json文件
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"column": [
"*"
],
"connection": [
{
"jdbcUrl": [
"${readerJdbcUrl}?useUnicode=true&characterEncoding=utf8&yearIsDateType=false&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false&rewriteBatchedStatements=true"
],
"table": [
"${stable}"
]
}
],
"username": "${readerUsername}",
"password": "${readerPassword}"
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"column": [
"*"
],
"connection": [
{
"jdbcUrl": "${writerJdbcUrl}?useUnicode=true&characterEncoding=utf8&yearIsDateType=false&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false&rewriteBatchedStatements=true",
"table": [
"${stable}"
]
}
],
"username": "${writerUsername}",
"password": "${writerPassword}",
"writeMode": "${writeMode}"
}
}
}
],
"setting": {
"speed": {
"channel": 1
}
}
}
准备执行脚本.sh
vim mysql2mysql.sh
请根据自己的目录更改
- 执行文件存储 路径 /opt/datax/bin/mysqlTOmysql/mysqltables.txt
- datax 部署 路径 /opt/datax/bin/datax.py
#!/bin/bash
#数据源配置
readerJdbcUrl="jdbc:mysql://10.2.2.162:3306/abtc_interview"
readerUsername="ab_talk"
readerPassword="iQIpwUnd#o9P"
#目标数据配置
writerJdbcUrl="jdbc:mysql://10.100.11.44:3306/abtc_interview"
writerUsername="root"
writerPassword="myabsh@20190809."
writeMode="replace" #可选择 replace insert updata
#replace 根据目标数据源表的主键更新数据,如果数据主键存在就先删除数据才插入(先删除在插入)
#insert 直接插入(默认值)
#updata 更新已有的数据
cat /opt/datax/bin/mysqlTOmysql/mysqltables.txt | while read tables #读取 mysqltables.txt 里面的表名(一次读取一行并存入tables变量中)
do
echo "#######################迁移数据表 ${tables}#######################"
python /opt/datax/bin/datax.py -p "-DwriteMode=${writeMode} -Dstable=${tables} -DreaderJdbcUrl=${readerJdbcUrl} -DwriterJdbcUrl=${writerJdbcUrl} -DreaderUsername=${readerUsername} -DreaderPassword=${readerPassword} -DwriterUsername=${writerUsername} -DwriterPassword=${writerPassword}" /opt/datax/bin/mysqlTOmysql/mysql2mysql.json
done
文件都放在同一个目录下
更多属性:https://blog.csdn.net/weixin_42050545/article/details/93883887