PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 数据库 > MySQL教程 > 正文

    MySQLdb ImportError: libmysqlclient.so.18

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:导入数据时提示了ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory不是一个有...
    导入数据时提示了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
    再次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
    >>>
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-35-536-1.html
    相关热词搜索: MySQLdb