#导入第三方库
import pymysql as pl
# 连接数据库 的参数
参数的运用(
host :端口 一般为localhost
port :
database:要运用的数据库
charset :字符集:utf8
user:用户 为root
password :密码
)
db = pl.connect(
host = "127.0.9.9",port = "3307",database = "company",charset = "utf8", user = "root" ,password = "123456"
)
# 报异常的处理:
try:
db = pymysql.connect(host = "127.0.9.9",port = "3307",database = "company",charset = "utf8", user = "root" ,password = "123456")
print("mql登录成功!")
except pymysql.Error as e:
print("登录失败" + str(e))