import pymysql import paramiko sql_commands = [ "ALTER TABLE `fa_master` MODIFY COLUMN `work_status` enum('off','on') NOT NULL DEFAULT 'off' COMMENT '接单出工状态:off=暂停,on=听单接单中';", "UPDATE `fa_master` SET `work_status` = 'off' WHERE `verify_status` != 'pass';", ] alter_audittime = "ALTER TABLE `fa_master` ADD COLUMN `audittime` bigint(16) NULL DEFAULT NULL COMMENT '审核完成时间戳' AFTER `audit_msg`;" alter_admin_id = "ALTER TABLE `fa_master` ADD COLUMN `audit_admin_id` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '审核管理员ID' AFTER `audittime`;" print("1. Migrating Local DB...") conn = pymysql.connect(host='127.0.0.1', user='yjyf', password='4bRz2NYz6pDhsCk4', database='yjyf', port=3306) cur = conn.cursor() for sql in sql_commands: cur.execute(sql) print("Executed:", sql[:50]) # check columns cur.execute("SHOW COLUMNS FROM `fa_master` LIKE 'audittime'") if not cur.fetchall(): cur.execute(alter_audittime) print("Added audittime") cur.execute("SHOW COLUMNS FROM `fa_master` LIKE 'audit_admin_id'") if not cur.fetchall(): cur.execute(alter_admin_id) print("Added audit_admin_id") conn.commit() cur.execute("SELECT id, realname, mobile, work_status, verify_status FROM fa_master WHERE verify_status != 'pass'") print("Local non-pass masters now:", cur.fetchall()) conn.close() print("2. Migrating Remote DB (8.137.181.63)...") try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('8.137.181.63', port=22, username='root', password='liyanxia@6688', timeout=10) stdin, stdout, stderr = ssh.exec_command("mysql -uyjyf -pyjyf yjyf -e \"UPDATE fa_master SET work_status = 'off' WHERE verify_status != 'pass';\"") err = stderr.read().decode('utf-8', errors='ignore') if err: print("Update err:", err) stdin, stdout, stderr = ssh.exec_command("mysql -uyjyf -pyjyf yjyf -e \"ALTER TABLE fa_master MODIFY COLUMN work_status enum('off','on') NOT NULL DEFAULT 'off';\"") err = stderr.read().decode('utf-8', errors='ignore') if err: print("Alter err:", err) stdin, stdout, stderr = ssh.exec_command("mysql -uyjyf -pyjyf yjyf -e \"SELECT id, realname, mobile, work_status, verify_status FROM fa_master WHERE verify_status != 'pass';\"") print("Remote non-pass masters now:\n" + stdout.read().decode('utf-8', errors='ignore')) ssh.close() except Exception as e: print("SSH migration error:", e)