MySQLdb._exceptions.OperationalError:(2002,“无法连接到本地主机上的MySQL服务器(10048)”)

时间:2019-05-10 23:20:15

标签: python mysql flask

我用来执行以下查询

        connection= MySQLdb.connect(host=self.__host, user=self.__db_username, passwd=self.__db_passwd, db=self.__db, charset="utf8", use_unicode=True)
        cursor= connection.cursor()
        sql= 'SELECT * FROM func1'
        cursor.execute(sql)
        data= cursor.fetchall()
        cursor.close()
        connection.close()
        func1 = None

        if len(data)>0:
            func1s = []
            for item in data:
                func1= db_func1()
                #item = data[0]
                func1.id = item[0]
                func1.title = item[2]


                func1s.append(func1)
            return func1s

它将第一次执行,但是一秒钟后它将给我错误,我正在使用端口3306

感谢您的帮助

  File "C:\Users\elham\AppData\Local\Programs\Python\Python37\lib\site-packages\MySQLdb\connections.py", line 164, in __init__    super(Connection, self).__init__(*args, **kwargs2)MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on 'localhost' (10048)") ```



0 个答案:

没有答案