operationalError 2002, mysql on osx 10.9

33 views
Skip to first unread message

Mark Phillips

unread,
May 2, 2007, 10:09:28 AM5/2/07
to Django users
Being a newbie has its challenges...

Before going any further on the answers to my earlier post, I thought
I should walk through the setup process once more.

I set up a new app. I can load the "it worked!" page using a browser
on the localhost with "runserver". When I ran the "manage.py syncdb"
method as part of walking through the project setup process, it threw
an exception, see traceback below.

The server is running mysql, I use phpMyAdmin and a couple of other
applications successfully with it.
There is an existing database of the same name as the new django
project.
I didn't find anything interesting in the logs, but then the django
logs are empty at the moment.
I did not find a file at "/tmp/mysql.sock"

I found some references to the 2002 error but they seemed to be
problems of whether mysql was running or installed.

Can someone point me in the right direction?

- Mark

Traceback
=========
admin$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 11, in ?
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/
management.py", line 1319, in execute_manager
execute_from_command_line(action_mapping, argv)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/
management.py", line 1243, in execute_from_command_line
action_mapping[action]()
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/Django-0.95.1-py2.4.egg/django/core/
management.py", line 446, in syncdb
cursor = connection.cursor()
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/Django-0.95.1-py2.4.egg/django/db/backends/
mysql/base.py", line 90, in cursor
self.connection = Database.connect(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/MySQLdb/__init__.py", line 66, in Connect
return Connection(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/MySQLdb/connections.py", line 134, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local
MySQL server through socket '/tmp/mysql.sock' (2)")


settings.py
=========
DATABASE_ENGINE = 'mysql' # 'postgresql', 'mysql',
'sqlite3' or 'ado_mssql'.
DATABASE_NAME = 'FirstDjango' # Or path to database file
if using sqlite3.
DATABASE_USER = 'some_name' # Not used with sqlite3.
DATABASE_PASSWORD = 'some_string' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost.
Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not
used with sqlite3.

Michael K

unread,
May 2, 2007, 3:25:26 PM5/2/07
to Django users
On May 2, 10:09 am, Mark Phillips <m...@mophilly.com> wrote:
> Being a newbie has its challenges...

I know exactly what you mean.

> The server is running mysql, I use phpMyAdmin and a couple of other
> applications successfully with it.
> There is an existing database of the same name as the new django
> project.
> I didn't find anything interesting in the logs, but then the django
> logs are empty at the moment.
> I did not find a file at "/tmp/mysql.sock"

The error involving not being able to open the /tmp/mysql.sock usually
has to do with host resolution OR the server being down (we've ruled
that one out). Simply put, your mysql isn't listening on a UNIX
socket, but an actually IP address (be it a normal one, or 127.0.0.1),
but the application is trying to open the UNIX socket, instead of the
IP socket.

Try setting DATABASE_HOST to 'localhost' instead of blank. What OS
are you running this on?

HTH,

Michael

Michael K

unread,
May 2, 2007, 3:26:56 PM5/2/07
to Django users
On May 2, 3:25 pm, Michael K <m...@arikel.net> wrote:
>
> Try setting DATABASE_HOST to 'localhost' instead of blank. What OS
> are you running this on?

This will teach me to read the subject closely. I should have went
with my gut feeling that it was Mac OS X :)


Michael

Mark Phillips

unread,
May 2, 2007, 3:36:01 PM5/2/07
to django...@googlegroups.com

Thank you, Michael. 'localhost' did not work but '127.0.0.1' did.

Happy days,

- Mark

Mark Phillips

unread,
May 2, 2007, 3:36:43 PM5/2/07
to django...@googlegroups.com

No problem, Michael. All is well.

- Mark

Reply all
Reply to author
Forward
0 new messages