简体   繁体   中英

install mysql-python on OS X 10.8

After running MySQL-python 1.2.4 setup.py I get the following error trying to use: import MySQLdb:

$ python mysqldb_module.py

Traceback (most recent call last):
  File "mysqldb_module.py", line 1, in <module>
    import MySQLdb
  File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4-py2.7-macosx-10.8-intel.egg/MySQLdb/__init__.py", line 19, in <module>
    import _mysql

ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib

  Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4-py2.7-macosx-10.8-intel.egg/_mysql.so
  Reason: image not found

Anyone got some wisdom to impart?

We need to do a few things from a command prompt. Note that commands need to be copied/pasted starting after the “$” prompt in the examples. Open up Terminal and issue this command:

user@computer:$ vi .bash_profile

Use the 'i' key to go into insert mode, then paste in this line:

export PATH=$PATH:/usr/local/mysql/bin

Hit the 'Esc' key to exit insert mode and type “:wq” and hit enter to write and quit the editor. Close the terminal window and open a new one. You can then enter this command:

user@computer:$ mysql -u root

Enter the following command into the MySQL prompt, change 'mypass' to be a secure password for the MySQL root user. GRANT ALL ON . TO 'root'@'localhost' IDENTIFIED BY 'mypass' WITH GRANT OPTION; quit The last command we'll need to run in terminal will allow Apache and PHP to access MySQL:

user@computer:$ sudo mkdir /var/mysql; sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM