python mysql_replicationa安装
时间: 2024-03-16 10:20:42 浏览: 114
1. 安装依赖库
```shell
yum install -y python-devel mysql-devel mysql
```
2. 安装pip
```shell
yum install -y epel-release
yum install -y python-pip
```
3. 安装mysql-replication
```shell
pip install mysql-replication
```
4. 测试
```python
from mysql_replication import BinLogStreamReader
mysql_settings = {
"host": "localhost",
"port": 3306,
"user": "root",
"passwd": "password"
}
stream = BinLogStreamReader(
connection_settings=mysql_settings,
server_id=100,
blocking=True,
only_events=["write_rows_event"],
only_tables=["test"],
resume_stream=True,
)
for binlogevent in stream:
for row in binlogevent.rows:
print(row)
stream.close()
```
以上代码会监听 MySQL 数据库的 test 表中的写操作,并打印出写入的数据。
阅读全文
相关推荐













