简体   繁体   English

在OS X 10.8上安装mysql-python

[英]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: 运行MySQL-python 1.2.4 setup.py后,尝试使用以下错误: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: 使用“ i”键进入插入模式,然后粘贴以下行:

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. 按“ Esc”键退出插入模式,然后键入“:wq”,然后按Enter键编写并退出编辑器。 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. 在MySQL提示符下输入以下命令,将“ mypass”更改为MySQL根用户的安全密码。 GRANT ALL ON . 授予所有 TO 'root'@'localhost' IDENTIFIED BY 'mypass' WITH GRANT OPTION; 以GRANT OPTION选项将'mypass'标识为'root'@'localhost'; quit The last command we'll need to run in terminal will allow Apache and PHP to access MySQL: quit我们将需要在终端中运行的最后一个命令将允许Apache和PHP访问MySQL:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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