V
V
Vahe2016-01-28 16:56:17
MySQL
Vahe, 2016-01-28 16:56:17

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()

I was hoping this would connect but I see an error.
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

1 answer(s)
S
sim3x, 2016-01-28
@sim3x

isup.me/mysql.hostinger.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question