cant execute query
已经使用pip install pymymql安装了pymysql
`import pymysql
db = pymysql.connect(host='localhost',user='root',passwd='')
cursor = db.cursor()
query = ("SHOW DATABASES")
cursor.execute(query)
for r in cursor:
print (r)`
enter code here
回溯(最近通话最近): 文件“ C:\ Users \ Ironman \ Desktop \ testdbase.py”,第2行,在 db = pymysql.connect(host ='localhost',user ='root',passwd ='') 连接中第94行的文件“ C:\ Users \ Ironman \ AppData \ Local \ Programs \ Python \ Python37-32 \ pymysql__init __。py” 返回Connection(* args,** kwargs) init 中的文件“ C:\ Users \ Ironman \ AppData \ Local \ Programs \ Python \ Python37-32 \ pymysql \ connections.py”,第325行 self.connect() 连接中的文件“ C:\ Users \ Ironman \ AppData \ Local \ Programs \ Python \ Python37-32 \ pymysql \ connections.py”,行585 self._request_authentication() _request_authentication中的文件“ C:\ Users \ Ironman \ AppData \ Local \ Programs \ Python \ Python37-32 \ pymysql \ connections.py”,行847 auth_packet = self._read_packet() _read_packet中的文件“ C:\ Users \ Ironman \ AppData \ Local \ Programs \ Python \ Python37-32 \ pymysql \ connections.py”,第670行 packet.check_error() 文件“ C:\ Users \ Ironman \ AppData \ Local \ Programs \ Python \ Python37-32 \ pymysql \ protocol.py”,第220行,在check_error中 err.raise_mysql_exception(self._data) 在“ c:\ Users \ Ironman \ AppData \ Local \ Programs \ Python \ Python37-32 \ pymysql \ err.py”文件中,第104行,在raise_mysql_exception中 引发errorclass(errno,errval) pymysql.err.OperationalError:(1045,“用户'root'@'localhost'的访问被拒绝(使用密码:否)“)
答案 0 :(得分:0)
刚错过了我的xampp中的9321端口:D