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

应该就好用了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值