Pymysql

pymsql is avilable with python3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import pymysql

conn = pymysql.connect(host='127.0.0.1', port=3306, user='user', passwd='pass', db='db_name', charset='utf8')
cursor1 = conn.cursor()
cursor2 = conn.cursor()
cursor3 = conn.cursor()

ids = cursor1.execute("select id from users")
for i in range(0, ids - 1):
id= cursor1.fetchone()
cursor2.execute("select name from clients where id = %s ", id)
name = cursor2.fetchone()
cursor3.execute("update clients set str_name = %s where id = %s ", (name, id))
cursor1.close
cursor2.close
cursor3.close
conn.commit()
conn.close()