Home >  > Python远程连接Mysql

Python远程连接Mysql

一、设定数据库的连接
设定hostname为%,也即让navicat连接数据库同样的设定。

二、代码连接

import pymysql
con = pymysql.connect(host='xxx.xxx.164.47',port=3306, user='dbwfornavicat', password='10%F4', database='sunrxxx', charset='utf8')
cursor = con.cursor()

cursor.execute('''select * from ask_users ''')
results = cursor.fetchall()
for row in results:
    print(row)

暧昧帖

本文暂无标签