Answer the question
In order to leave comments, you need to log in
Python connect to MySQL database on web server?
I would like to know the process of connecting to a MySQL database hosted on a web server.
import MySQLdb
# Открыть соединение с базой данных
db = MySQLdb.connect("mysql.hostinger.ru","<user>","<password>","<db_name>" )
# Подготовить объект курсора, используя метод cursor()
cursor = db.cursor()
# Выполнить SQL запрос, используя метод execute().
cursor.execute("SELECT VERSION()")
# Fetch метод один ряд с помощью fetchone().
data = cursor.fetchone()
print "версия баз : %s " % data
# Отключение от сервера
db.close()
Traceback (most recent call last):
File "C:\Users\Admin\Documents\py\gui.py", line 8, in <module>
db = MySQLdb.connect("mysql.hostinger.ru"," ************","*******","************" )
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2005, "Unknown MySQL server host 'mysql.hostinger.ru' (0)")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question