解决MySQLdb ImportError: libmysqlclient.so.18错误
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-24 16:47:31 浏览: 评论:0
今天尝试使用MySQLdb数据库结果发现安装好MySQLdb我们导入数据时提示了ImportError:libmysqlclient.so.18: cannot open shared object file:No such file or directory不是一个有效的目录了,下面我就来把解决方法与各位分享一下.
安装MySQLdb后,import MySQLdb出错如下:
- [root@lizhong MySQL-python-1.2.3]# /usr/local/bin/python2.7
- Python 2.7.6 (default, Apr 10 2014, 15:45:39)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import MySQLdb
- /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /soft/MySQL-python-1.2.3 is being added to sys.path
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "MySQLdb/__init__.py", line 19, in <module>
- import _mysql
- File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module>
- 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
根据最后提示,应该是找不着一个libmysqlclient.so.18的文件,于是到mysql安装目录里找到这个文件并且做一个软连接到/usr/lib,代码如下:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
如果是64系统则,代码如下:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
再次import MySQLdb就正常了,代码如下:
- [root@lizhong MySQL-python-1.2.3]# /usr/local/bin/python2.7
- Python 2.7.6 (default, Apr 10 2014, 15:45:39)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import MySQLdb
- >>>//开源代码phpfensi.com
Tags: MySQLdb ImportError libmysqlclient
相关文章
- ·MySQLdb操作mysql数据库的类(2014-09-22)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)