How to connect database from cPanel to Desktop in python - 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")

Related

Python code to connect to MySQL database doesn't work on Google Colab

I wrote the code bellow. It works on a .py file on my computer but not while running on Google Colab)
import mysql
import mysql.connector as msql
from mysql.connector import Error
try:
conn = msql.connect(host='localhost',database='transport_db_hl' ,user='root',
password='******')#give ur username, password
except Error as e:
print("Error while connecting to MySQL now ", e)
My server status is like that:
You would need to make:
your mysql server publicly available (hint: https://phoenixnap.com/kb/mysql-remote-connection)
presumably enable port forwarding on your router (hint: https://www.noip.com/support/knowledgebase/general-port-forwarding-guide/)
find your public IP (hint: https://www.whatsmyip.org/)
and replace the "localhost" with your public IP in your code above

Why doesn't it connect to the database remotely Python?

I am writing an online application. Rented hosting on TimeWeb, created a database on the hosting. I successfully connected to it using Putty, but the problem is that I need to connect using pycharm. Don't be surprised that I'm making an ssh connection here, and not in the ssh terminal of pycharm, I'm just planning to create an .exe file.I tried to specify port 3306 and utf8 encoding, but it still didn't help. So what's my mistake?
import paramiko
import pymysql
host = "x.x.x.x"
port = 22
username ="cv86943"
password = "xxxxxx"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host,port,username,password)
print("1") #1 writes, so the connection to the hosting is successful
conn = pymysql.connect(host = "localhost",user = "cv86943_letter", password = "12345678", db = "cv86943_letter")
print("2") #But 2 does not write anymore
ssh.close()
UPD: returns an error
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([WinError 10061]...)

How to connect to a remote Windows machine to change mdb file using python?

I am new to Python and I am trying to make a script that connects to a remote windows machine and change mdb file there. I can’t figure out how to work with the WMI library.
When I need to change mdb file (Access database) on my machine, I just use pyodbc connect. For example like this:
connStr = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb)};'
r'DBQ=C:\Komax\Data\Topwin\DatabaseServer.mdb;')
cursor = connStr.cursor()
But now I need to run code on my machine so that it modifies the file (mdb) on the other machine. It seems like I have to use this code below to connect to remote machine, but I don't know what to do next, how to use connection. Please, help me to solve the problem :)
ip = "192.168.18.74"
username = "admin"
password = "komax"
from socket import *
try:
print("Establishing connection to %s" % ip)
connection = wmi.WMI(ip, user=username, password=password)
print("Connection established")
except wmi.x_wmi:
print("Your Username and Password of "+getfqdn(ip)+" are wrong.")

Can you connect to a database on another pc?

I'm using MySQLdb for python, and I would like to connect to a database hosted on an other PC on the same network/LAN.
I tried the followings for host:
192.168.5.37
192.168.5.37:3306
http://192.168.5.37
http://192.168.5.37:3306
None of the above work, I always get the
2005, Unknown MySQL server host ... (0)
What might be the problem?
Code:
db = MySQLdb.connect(host="192.168.5.37", user = "root" passwd = "password", db = "test1")
You can use MySQL Connector/Python, a standardized database driver for Python.
You must provide username, password, host, database name.
import mysql.connector
conn = mysql.connector.connect(user=username, password=password,
host="192.168.5.37",
database=databaseName)
conn.close()
You can download it from: https://dev.mysql.com/downloads/connector/python/
The IP you posted are local IPs
Give it a try with your external IP (for example on this website)
https://www.whatismyip.com/
If it works with the external IP, then it's maybe a misconfiguration of your firewall.

How to connect to remote mysql server in python

Hi i have a requirement where i need to connect to remote mysql server. My application shall be running on local machine and my mysql will be running on remote server.I have tried the following code:
DB = 'gts'
DB_HOST = 'ps95074.dreamhost.com'
DB_USER = 'root'
DB_PASSWORD = 'dbadminpassword'
conn = MySQLdb.Connection(db=DB, host=DB_HOST, user=DB_USER,passwd=DB_PASSWORD)
cursor = conn.cursor()
But i am getting the following error
OperationalError: (2005, "Unknown MySQL server host 'ps95074.dreamhost.com' (1)")
Instead if i use
DB_HOST='localhost'
Everything works fine. How can same be possible with remote host.Any help shall be appreciated.
Check your firewall. That server is online and available from any machines:
> mysql -h ps95074.dreamhost.com
ERROR 1045 (28000): Access denied for user 'myuser'#'myhost' (using password: NO)
However, even if you can connect chances are good that your database user only allows local connections.
Update: I just tried it again and now it also fails using the commandline client. So clearly something is wrong with your server.

Categories

Resources