dtmwnqng38644 2016-11-25 05:39
浏览 229

Python无法连接到MySQL

I'm trying to connect to a database on a Linux server, everything works fine with PHP using:

$mysqli= new mysqli($_DBHOST, $_DBUSER, $_DBPASS, $_DB);

I can also connect using the command line with:

mysql -u xxx -p

But when I try to connect with Python using pymysql I get the following error:

pymysql.err.InternalError: (1130, "Host 'xxx' is not allowed to connect to
this MariaDB server")

Python code:

import pymysql
conn = pymysql.connect(host="xxx",user='xxx', passwd='xxx', db = 'xxx',
                                   ,port=3306, autocommit=True)

How can this even be possible? It cannot be a permission issue since PHP can connect fine, or can it?

  • 写回答

3条回答 默认 最新

  • douguachi0056 2016-11-25 05:42
    关注

    Try this

        try:
            import mysql.connector
            mysql_connector = mysql.connector
        except:
            import pymysql
            mysql_connector = pymysql
    
        mysql_connector.connect(user='root', password='root', host='xxx:3306', database='test')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器