简体   繁体   中英

How to connect database from cPanel to Desktop in python

I am making an application in python - and need to connect to a web server database from the desktop.
How can I do this.

example:

if my site is xyz.com it's ip is 123.134.121.136 and my database name is xyz_code and name is xyz_alibaba and password is !@#!#1&#a#@

import MySQLdb as mdb

s_h = "123.134.121.136:3306"
s_u = "xyz_alibaba"
s_p = "!@#!#1&#a#@"
s_d = "softwar1_codexyz_code"

s_cn = mdb.connect(s_h, s_u, s_p, s_d)

if s_cn :
    print "ok"
else:
    print "no"

When I run this code it shows an unknown loaclhost error.

How can I fix it?

Have you added your ISP IP in remote mysql host access list? And enable port 3306 in your server firewall.

you choose wrong way to connect !!!

it's the code :

db = MySQLdb.connect(host="123.134.121.136",  
                     port=3306,  
                     user="xyz_alibaba",     
                     passwd="!@#!#1&#a#@", 
                     db="xyz_code")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM