0

I have followed the steps in the website below, and installed everyhting for MySQLdb.I am using Xampp for the database and I have linked the mysql_config to the xampp mysqlconfig. http://www.tutorialspoint.com/python/python_database_access.htm
However, after everything was installed and when I try to import it says:

Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so
  Reason: image not found

Thanks ahead of time for all your help!

Nazariy
  • 717
  • 6
  • 23
  • Are you aware of the fact that MySql has to downloaded and installed as a package ? Did you install using `pip` ? – d-coder Sep 28 '14 at 06:36
  • @sammy No I did not. I just downloaded the file from the website and followed their instructions.By the way, I am on a Mac. – Nazariy Sep 28 '14 at 06:39
  • Okay. But I'm using MySqldb too which works fine for me. My answer coming right up – d-coder Sep 28 '14 at 06:43
  • 2
    `and I have linked the mysql_config to the xampp mysqlconfig` - these are two different commands, so linking one to the other is going to break things rather than fix them. – Burhan Khalid Sep 28 '14 at 06:52
  • Ohhh! I think I misunderstood the mysql_config. What I just did is I used brew to install mysql. Then I did both python setup.py build and python setup.py install again. And now everything is working fine. Sorry I am still a beginner. However,can anyone please explain to me about the mysql_config. Also can I still use xampp database to connect to through python or no? Thank you! – Nazariy Sep 28 '14 at 07:06
  • @Nazariy1995: If installing MySQL before building MySQLdb solved your problem, then you should either (a) write a complete answer and accept it, or (b) close or delete your question. – abarnert Sep 28 '14 at 07:35

1 Answers1

0

What solved my problem is:

  1. Installed homebrew from this website:http://brew.sh
  2. Installed mysql using brew:

    brew install mysql

  3. Followed this website to build and install python MySQLdb:http://www.tutorialspoint.com/python/python_database_access.htm

After all of that everything is perfectly working.So if anyone is having trouble with MySQLdb on a Mac, then just follow those instructions. I hope this helps.

Nazariy
  • 717
  • 6
  • 23