• ADADADADAD

    解决python MySQLdb import Error问题[ mysql数据库 ]

    mysql数据库 时间:2024-12-24 19:10:44

    作者:文/会员上传

    简介:

    今天安装MySQLmtop的时候报错,发现没有安装python的MySQLdb模块,手动运行报如下错:
    [root@test1 mysqlmtop]# python
    Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
    [GCC

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。


    今天安装MySQLmtop的时候报错,发现没有安装python的MySQLdb模块,手动运行报如下错:
    [root@test1 mysqlmtop]# python
    Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import MySQLdb
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in <module>
    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
    >>> quit
    Use quit() or Ctrl-D (i.e. EOF) to exit
    >>>

    解决方法:
    root@test1 mysqlmtop]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
    [root@test1 mysqlmtop]#

    再次运行测试:
    [root@test1 mysqlmtop]# python
    Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import MySQLdb
    >>>
    >>> conn= MySQLdb.connect(
    ... host='172.16.16.14',
    ... port = 3306,
    ... user='root',
    ... passwd='123456',
    ... db ='test',
    ... )
    >>> cur = conn.cursor()
    >>>
    >>> cur.execute("select * from chenfeng")
    3L
    >>>
    >>> result = cur.fetchall()
    >>> print result
    (('aaaa',), ('bbbb',), ('bbbb',))
    >>>
    >>>


    解决python MySQLdb import Error问题.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: error解决mysqldb