Django mit MySQL connection

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
kostonstyle
User
Beiträge: 148
Registriert: Sonntag 2. November 2008, 12:13

Habe im Netz folgendes gefunden, werde diese mal versuchen

Code: Alles auswählen

While I'm unsure about the original post, (some extra details like what distribution your on may help) in regards to the MacBook Pro, if your on tiger/leopard (10.4/10.5) the mysql.sock file would actually be under either /var/mysql.sock or /tmp/mysql.sock depending on wether you installed it via either source or package.

On leopard to get the mysql bindings to work you need to do the following (this worked for me):

Install Mysql (I used the x64 Intel Community Installer Package from MySQLs Dev Site)

Create a Symlink (they moved the default socket from /var to /tmp for some unknown reason)

sudo mkdir /var/mysql/
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Install XCode Tools (if you haven't already as they're needed to compile the mysql bindings)
ms4py
User
Beiträge: 1178
Registriert: Montag 19. Januar 2009, 09:37

Laut http://code.djangoproject.com/ticket/1481 kannst du den Socket auch unter Host angeben genau wie da:
kostonstyle hat geschrieben:

Code: Alles auswählen

DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'example'             # Or path to database file if using sqlite3.
DATABASE_USER = 'webdev'             # Not used with sqlite3.
DATABASE_PASSWORD = 'xxxxxx'         # Not used with sqlite3.
DATABASE_HOST = '/tmp/mysql.sock'             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
Kommt da die selbe Fehlermeldung?
kostonstyle
User
Beiträge: 148
Registriert: Sonntag 2. November 2008, 12:13

das habe ich ja schon gemacht, aber das klappte auch nicht.
ms4py
User
Beiträge: 1178
Registriert: Montag 19. Januar 2009, 09:37

kostonstyle hat geschrieben:das habe ich ja schon gemacht, aber das klappte auch nicht.
ice2k3 hat geschrieben:Kommt da die selbe Fehlermeldung?
Edit:

Noch eine Idee

Code: Alles auswählen

import MySQLdb
import sys

try:
    conn = MySQLdb.connect (host = "127.0.0.1",
                        user = "webdev",
                        passwd = "xxxxxx",
                        db = "web")
    cursor = conn.cursor()
    cursor.execute ("""SELECT id, data FROM example""")
    row = cursor.fetchall()
    for r in row:
        print(r)
    cursor.close()
    conn.close()
except MySQLdb.Error, e:
    print "Error %d: %s" % (e.args[0], e.args[1])
    sys.exit(1) 
Funktioniert das auch? (Will damit feststellen, ob dein MySQL überhaupt TCP-Verbindungen aktzeptiert)
ms4py
User
Beiträge: 1178
Registriert: Montag 19. Januar 2009, 09:37

kostonstyle
User
Beiträge: 148
Registriert: Sonntag 2. November 2008, 12:13

nun funktioniert es einwandfrei, die Einstellungen waren richtig nur habe ich die falschen Daten genommen.
Vielen Dank für eure Mühe und Verständis.
Antworten