cursor()和connection()方法在尝试通过Python(使用Pycharm)连接MySQL时不起作用

问题描述 投票:0回答:1

我正在尝试通过python连接MySQL数据库。我最初安装的mysql-connector无法正常工作。后来我安装了mysql-connector-python,连接成功。但是当我尝试使用cursor()时,出现错误:

代码:

导入_mysql_connector

mydb = _mysql_connector.MySQL()。connect(host =“ localhost”,user =“ root”,password =“ 1234”)] >>

mycursor = mydb.cursor()

mycursor.execute(“显示数据库”)

错误:AttributeError:'NoneType'对象没有属性'cursor'

我正在尝试通过python连接MySQL数据库。我最初安装的mysql-connector无法正常工作。后来我安装了mysql-connector-python,连接成功。但是当我尝试...

mysql python-3.x mysql-connector-python
1个回答
0
投票

您正在尝试使用C Extension Module进行连接。这是基本的Connector示例:

© www.soinside.com 2019 - 2024. All rights reserved.