通过Python连接到远程MySQL数据库 [英] Connect on remote MySQL database through Python

查看:489
本文介绍了通过Python连接到远程MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下脚本,但不幸的是,该脚本无法正常工作.我正在使用免费的MySQL数据库提供程序.有什么想法吗?

I have tried the following script but unfortunately doesn't work. I am using a free MySQL database provider. Any ideas?

import MySQLdb

myDB = MySQLdb.connect(host="208.11.220.249",port=3306,user="XXXXX",passwd="XXXXX",db="XXXXX")
cHandler = myDB.cursor()
cHandler.execute("SHOW DATABASES")
results = cHandler.fetchall()
for items in results:
    print items[0]

当前,我遇到以下错误:

Currently, I am getting the following error:

super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user 'XXXXX'@'%' to database 'XXXXX'")

推荐答案

 GRANT ALL
 ON  *.*
 TO user@192.168.39.17  -- client ip address
 IDENTIFIED BY 'pwd';

修改

这是您在数据库上运行的SQL,以确保user可以访问所有内容. pwduser的密码.

This is SQL that you'd run on the database in order to ensure that the user has access to everything. pwd is the user's password.

基本上,此答案假定连接问题是凭据问题.

Basically, this answer assumes that the connection issue is a credentials issue.

这篇关于通过Python连接到远程MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆