MySQL
- Container preparation
docker pull mysql:5.6
docker run -p 3306:3306 --name hello_mysql -d -e MYSQL_ROOT_PASSWORD=root mysql:5.6
docker exec -it hello_mysql bash
- data preparation
mysql -uroot -proot
Connect to mysql
- Create a database first
create database db_datax;
use db_datax
- Create a table and insert data
create table if not exists tb_employee (id int, salary int);
truncate table tb_employee ;
insert into tb_employee (id, salary) values ('1', '100');
insert into tb_employee (id, salary) values ('2', '200');
insert into tb_employee (id, salary) values ('3', '300');
After the data is ready, you can exit the container, but do not close it
- View ip
docker inspect --format='{ {.NetworkSettings.IPAddress}}' hello_mysql
DataX
ping 172.17.0.3
First test whether the DataX container can access the MySQL container. Generally speaking, the default network is used, and the two containers should be able to communicate normally.
cd /opt/modules/datax
vi ./job/mysql2stream.json
{
"job": {
"setting": {
"speed": {
"channel": 3
},
"errorLimit": {
"record": 0,
"percentage": 0.02
}
},
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root",
"password": "root",
"column": [
"id",
"salary"
],
"splitPk": "id",
"connection": [
{
"table": [
"tb_employee"
],
"jdbcUrl": [
"jdbc:mysql://172.17.0.3:3306/db_datax"
]
}
]
}
},
"writer": {
"name": "streamwriter",
"parameter": {
"print":true
}
}
}
]
}
}
python ./bin/datax.py ./job/mysql2stream.json