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
{
"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
}
}
}
vim mysql2mysql.sh
请根据自己的目录更改
#!/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