python链接mysql数据库

1.安装pycharm python3.6    pip

在windows+R  cmd  

where pip

pip install mysql-client

如何看自已mysql-client有没有装成功

python

import mysql-client

import MySQLdb

con = MySQLdb.connect(
host='127.0.0.1',
user='root',
passwd='',
port=3308,
db='news',
charset='utf8'
)

cursor = con.cursor()
cursor.execute('SELECT * FROM `news`')
rest = cursor.fetchone()
print(rest)

原文地址:https://www.cnblogs.com/xuzhongtao/p/8984577.html