python 写linux mysql_(linux)python之mysql数据库操作环境搭建
剛搭建完redis的環境累個半死,剛又弄了一個mysql的環境,遇到多種問題先簡單記錄,以備不時之需
1、首先mysql、python環境肯定要有吧!
假定mysql安裝在/usr/local/mysql
2、下載MySQL-python-1.2.3.tar.gz 并解壓
解壓:tar zxvf MySQL-python-1.2.3.tar.gz
3、進入 MySQL-python-1.2.3?修改setup_posix.py文件
visetup_posix.py
修改行:#mysql_config.path = "mysql_config"#注釋掉 為:mysql_config.path ="/usr/local/mysql/bin/mysql_config"
若果不修改會報錯誤:mysql_config not found
原因:mysql_config命令沒有找到。
4、在保證有setuptools的情況下執行以下三個代碼(如果沒有setuptools,請參考上一篇文)
sudo python setup.py build
sudo python setup.py install
如果報錯出現error: command 'gcc' failed with exit status 1的解決方法
>>> yum install MySQL-p*
>>>yum install python-devel
>>>cd MySQL-python-1.2.3
>>> python setup.py build
>>> python setup.py install
5、精華:
報錯:./directadmin: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
或:
Traceback (most recent call last):
File "existuser.py", line 2, in
import MySQLdb
File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in
File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in
File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
是mysql-lib無法正確加載導致的
將/usr/local/mysql/lib 下的libmysqlclient.so.16 或?libmysqlclient.so.18 文件在/usr/lib下建立軟連接
ln -s /usr/local/mysql/lib/libmysqlclient.so.16/usr/lib/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
如出現:“File exists” ?!! ?該文件之前指向了錯誤的路徑 ?刪除之后重新建立
如果還是不好使,可能是/usr/lib沒有被加載調用。添加配置:
系統要確認動態庫的地址,把動態庫的路徑放到/etc/ld.so.conf中
建議:在/etc/ld.so.conf.d/上新建動態庫相應的文件配置文件*.conf,
在該文件中填上該動態庫的絕對路徑
此例:
vim /etc/ld.so.conf.d/ld.mysql.so.conf
/usr/local/mysql/lib
運行 ldconfig 重建 /etc/ld.so.cache
應該就好用了
總結
以上是生活随笔為你收集整理的python 写linux mysql_(linux)python之mysql数据库操作环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql show slave_Mys
- 下一篇: mysql int 补零_mysql i