61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
import pymysql
|
|
from sshtunnel import SSHTunnelForwarder
|
|
|
|
|
|
server = SSHTunnelForwarder(
|
|
ssh_address_or_host=("1.15.182.107", 22),
|
|
ssh_username="root",
|
|
ssh_password="`NS?VGg@7]~F3}p",
|
|
remote_bind_address=("127.0.0.1",3306),
|
|
local_bind_address=('127.0.0.1',5143)
|
|
)
|
|
|
|
server.start()
|
|
db_host = server.local_bind_host
|
|
db_port = server.local_bind_port
|
|
|
|
conn = pymysql.connect(
|
|
host=db_host,
|
|
port=db_port,
|
|
user="root",
|
|
password="Z4rf7eZZe500dxa",
|
|
database="pet_home_5"
|
|
)
|
|
|
|
cursor = conn.cursor()
|
|
cursor.execute("select `dwUin`, `rolecreatetime` from t_player_baseinfo")
|
|
result = cursor.fetchall()
|
|
|
|
server2 = SSHTunnelForwarder(
|
|
ssh_address_or_host=("8.155.14.94", 22),
|
|
ssh_username="root",
|
|
ssh_password="-xLX]p!PQ1@SHm`A",
|
|
remote_bind_address=("rm-f8zd2030feam53n43.mysql.rds.aliyuncs.com",3306),
|
|
local_bind_address=('127.0.0.1',5144)
|
|
)
|
|
|
|
server2.start()
|
|
db_host2 = server2.local_bind_host
|
|
db_port2 = server2.local_bind_port
|
|
|
|
conn2 = pymysql.connect(
|
|
host=db_host2,
|
|
port=db_port2,
|
|
user="root",
|
|
password="Z4rf7eZZe500dxa",
|
|
database="pet_home"
|
|
)
|
|
|
|
cursor2 = conn2.cursor()
|
|
for i in result:
|
|
cursor2.execute("INSERT INTO log_login (`Uid`, `Event`, Timestamp) VALUES (%s, 'register', %s)", (i[0], i[1]))
|
|
print(i)
|
|
conn2.commit()
|
|
|
|
cursor2.close()
|
|
conn2.close()
|
|
server2.stop()
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
server.stop() |