沒(méi)有數(shù)據(jù)庫(kù)支持的程序都是耍流氓
安裝mysql驅(qū)動(dòng)
在下面的網(wǎng)址下載mysqldb模塊:
http://sourceforge.net/projects/mysql-python/
不用懷疑,2010年的版本;
在mac os x直接雙擊解壓,命令行進(jìn)入解壓后的目錄, 執(zhí)行python setup.py build
python setup.py install
運(yùn)行后發(fā)現(xiàn)沒(méi)有安裝mysql,這個(gè)時(shí)候編譯python-mysql可能無(wú)法通過(guò),抓緊下載mysql for mac
www.baidu.com上搜索mysql for mac,下載安裝
安裝方法,請(qǐng)參考
https://dev.mysql.com/downloads/mysql/
下載dmg版本,300M+
編譯python setup.py build報(bào)錯(cuò)
sh: mysql_config: command not found Traceback (most recent call last): File "setup.py", line 18, in <module> metadata, options = get_config() File "/Users/tuanwei/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "/Users/tuanwei/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found SdeMacBook-Air:MySQL-python-1.2.4b4 tuanwei$ python setup.py build sh: mysql_config: command not found Traceback (most recent call last): File "setup.py", line 18, in <module> metadata, options = get_config() File "/Users/tuanwei/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "/Users/tuanwei/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found
這里需要修改python-mysql中的site.cfg中的關(guān)于mysql_config的配置,打開(kāi)site.cfg.找到mysql_config,去掉注釋,修改到/usr/local/mysql/bin(默認(rèn)安裝后的mysql,會(huì)在此目錄下生成mysql_config文件)
修改后,編譯通過(guò),很快。
SdeMacBook-Air:MySQL-python-1.2.4b4 tuanwei$ python setup.py build running build running build_py creating build creating build/lib.macosx-10.12-x86_64-2.7 copying _mysql_exceptions.py -> build/lib.macosx-10.12-x86_64-2.7 creating build/lib.macosx-10.12-x86_64-2.7/MySQLdb copying MySQLdb/__init__.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb copying MySQLdb/converters.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb copying MySQLdb/connections.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb copying MySQLdb/cursors.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb copying MySQLdb/release.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb copying MySQLdb/times.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb creating build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.12-x86_64-2.7/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.macosx-10.12-x86_64-2.7 clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/local/mysql/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.12-x86_64-2.7/_mysql.o -fno-omit-frame-pointer -arch x86_64 _mysql.c:1563:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] if (how < 0 || how >= sizeof(row_converters)) { ~~~ ^ ~ 1 warning generated. clang -bundle -undefined dynamic_lookup build/temp.macosx-10.12-x86_64-2.7/_mysql.o -L/usr/local/mysql/lib -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/sqlite/lib -lmysqlclient -o build/lib.macosx-10.12-x86_64-2.7/_mysql.so -arch x86_64
安裝mysql-python完成,修改環(huán)境變量
打開(kāi)終端,在終端中使用vim打開(kāi)“~/.bash_profile”,如果沒(méi)有安裝vim,那就顯示隱藏文件用文本編輯器打開(kāi),具體操作這里就不復(fù)述了。在.bash_profile中添加以下內(nèi)容:
PATH="/usr/local/mysql/bin:${PATH}" export PATH export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ export VERSIONER_PYTHON_PREFER_64_BIT=no export VERSIONER_PYTHON_PREFER_32_BIT=yes
啟動(dòng)mysql
打開(kāi)控制面板,找到mysql控制臺(tái),啟動(dòng)mysql
找到python操作mysql的樣例,修改mysql的配置文件
下載mysql for mac的客戶端
https://dev.mysql.com/downloads/workbench/
很郁悶,下載后登錄不了,修改root密碼
mac上安裝mysql路徑: /usr/local/mysql/
修改root密碼
cd /usr/local/mysql/bin sudo su ./mysqld_safe --skip-grant-tables
重新打開(kāi)一個(gè)終端
cd /usr/local/mysql/bin mysql flush privileges; set password for 'root'@'localhost'=password('fith2017');
退出后,kill掉進(jìn)程
kill -9 mysqld_safe
添加mysql環(huán)境
打開(kāi)一個(gè)終端
命令:vim ~/.bash_profile
最后一行添加 PATH=$PATH:/usr/local/mysql/bin
,保存退出
命令source ~/.bash_profile
這里編譯還有可能出現(xiàn)異常
_mysql.c:44:10: fatal error: 'my_config.h' file not found
這是因?yàn)閄AMPP等,如果是IDE安裝的話,沒(méi)有編譯環(huán)境,所以需要單獨(dú)安裝mysql-connector-c或者重新安裝mysql
brew install mysql-connector-c