当前位置:首页 > 编程教程 > mysql技术文章 > MySQL-Python安装问题小记

MySQL-Python安装问题整理

  • 发布时间:
  • 作者:码农之家
  • 点击:272

这篇文章主要知识点是关于MySQL、Python、的内容,如果大家想对相关知识点有系统深入的学习,可以参阅以下电子书

PHP+MySQL程序设计及项目开发
  • 类型:PHP+MySQL大小:105.1MB格式:PDF作者:郑广成,朱翠苗
立即下载

MySQL-Python安装问题小记

安装完mysql-python后import加载模块提示以下错误,

 

复制代码 代码如下:

ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory

 

于是google之,总结一下解决方法:

(1)在mysql-ython的安装目录下找到site.cfg,将

#mysql_config = XXXXXXXXXXXXXXXX

 

注释符号去掉,并填上mysql_config的地址

(2)将mysql/lib下所有关于libmysqlclient的so文件软链接到/usr/lib下。

 

ln -s /usr/local/mysql/lib/mysql/libmysqlclient* /usr/lib
ldconfig

 

这样在加载

 

import _mysql

 

的时候就不会出错了

 

ubuntu 安装mysql-python遇到的问题

版本是python 2.6

使用easy_install 安装MySQL-python

easy_install "MySQL-python==1.2.3"
提示:error: Setup script exited with error: command 'gcc' failed with exit status 1

需要安装 python-devel
sudo apt-get install python-dev
#apt-get install python-devel
再使用easy_install 安装就可以

如果使用python setup.py 安装,提示mysql_config找不到
EnvironmentError: mysql_config not found
需要安装下面2个开发包,需要注意的是apt-get里面是没有的,我使用新立德软件包管理器安装

libmysqld-dev
libmysqlclient-dev

安装完成以后需要修改MySQL-python-1.2.3文件夹下面的setup_posix.py中的第26行,

mysql_config.path = "mysql_config"改为mysql_config的路径

whereis mysql_config查找路径

mysql_config.path = "/usr/bin/mysql_config"

再使用
python setup.py build
python setup.py install
就可以

ubuntu root 权限
sudo -i

安装MySQL-python问题解决

今天在centos安装MySQL-python,结果报错,报错信息如下:

 Running command /home/yunpeng.jiangyp/sys/python/bin/python -c "import setuptools;__file__='/home/admin/jyp/build/MySQL-python/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-MH5Aya-record/install-record.txt
 running install
 running build
 running build_py
 copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
 running build_ext
 building '_mysql' extension
 gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/home/yunpeng.jiangyp/sys/python/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv
 _mysql.c:44:23: error: my_config.h: No such file or directory
 _mysql.c:46:19: error: mysql.h: No such file or directory
 _mysql.c:47:26: error: mysqld_error.h: No such file or directory
 _mysql.c:48:20: error: errmsg.h: No such file or directory
 _mysql.c:88: error: expected specifier-qualifier-list before ‘MYSQL'
 _mysql.c:102: error: expected specifier-qualifier-list before ‘MYSQL_RES'

google找到答案(http://stackoverflow.com/questions/13044201/install-mysql-python-return-error-in-centos),需要先安装mysql-devel.x86_64,通过

sudo yum install mysql-devel.x86_64

再次安装成功

[yunpeng.jiangyp@v010105 ~]$ pip install MySQL-python
Downloading/unpacking MySQL-python
 Running setup.py egg_info for package MySQL-python
 
Installing collected packages: MySQL-python
 Running setup.py install for MySQL-python
 building '_mysql' extension
 gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/home/yunpeng.jiangyp/sys/python/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv
 gcc -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -o build/lib.linux-x86_64-2.7/_mysql.so
 
Successfully installed MySQL-python
Cleaning up...

以上就是本次给大家分享的关于java的全部知识点内容总结,大家还可以在下方相关文章里找到相关文章进一步学习,感谢大家的阅读和支持。

您可能感兴趣的文章:

  • Python备份MySQL数据库的代码详解
  • python进行MySQL数据库信息修改
  • Python3连接SQLServer、Oracle、MySql实例代码
  • Python中使用aiomysql异步操作MySQL实例效果
  • python3 pandas 如何读取MySQL数据和插入
  • MySQL 相关电子书
    学习笔记
    网友NO.583962

    Python备份MySQL数据库的代码详解

    本文实例讲述了Python实现备份MySQL数据库的方法。分享给大家供大家参考,具体如下: #!/usr/bin/env python# -*- coding:utf-8 -*-#导入模块import MySQLdbimport timeimport datetimeimport os Purpose: 备份数据库 Created: 2015/5/12 Modified:2015/5/12 @author: guoyJoedbUser=rootdbPasswd=rootdbHost=192.168.1.6dbCharset = utf8backupDir = /u02/backup/mysqlbackupDate = time.strftime(%Y%m%d)#查出MySQL中所有的数据库名称sqlStr1 = show databases like db%try: connDB= MySQLdb.connect(192.168.1.6,root,root,test ) connDB.select_db(test) curSql1=connDB.cursor() curSql1.execute(sqlStr1) allDatabase = curSql1.fetchall() print The database backup to start! %s %time.strftime(%Y-%m-%d %H:%M:%S) for db in allDatabase: dbName = db[0] fileName = %s/%s_%s.sql %(backupDir,backupDate,dbName) print fileName if os.path.exists(fileName): os.remove(fileName) os.system(mysqldump -h%s -u%s -p%s %s --default_character-set=%s %s/%s_%s.sql %(dbHost,dbUser,dbPasswd,dbName,dbCha……

    网友NO.103289

    python制作mysql数据迁移脚本

    用python写了个数据迁移脚本,主要是利用从库将大的静态表导出表空间,载导入到目标实例中。 #!/usr/bin/env python3#-*- coding:utf8 -*-#author:zhanbin.liu#!!!!!DB必须同版本#python3环境 pip3 install pymysql paramikoimport os#from pathlib import Pathimport sysimport pymysqlimport paramiko#每次只能迁移一个DB下的表,到指定DB#GRANT SELECT, CREATE, RELOAD, ALTER, LOCK TABLES ON *.* TO 'data_migration'@'192.168.%' IDENTIFIED BY 'data_migration@123';tables='sqlauto_cluster,sqlauto_user' #以,分割的字符串,如a,b,ctableList = tables.split(',')sourceIp = '192.168.1.101'sourceDataBase = '/data/mysql/3306/data'sourceDbName = 'inception_web'sourceDataDir = os.path.join(sourceDataBase,sourceDbName)desIp = '192.168.1.102'desDataBase = '/data/mysql/3306/data'desDbName = 'inception_web'desDataDir = os.path.join(desDataBase,desDbName)# for table in tableList:# desFile = Path("%s/%s.ibd" %(desDataDir,table))# print(desFile)# if desFile.is……

    网友NO.228168

    python查询mysql,返回json的实例

    如下所示: import MySQLdbimport jsondef getSql(): try: con = MySQLdb.connect(host='localhost', user='', passwd='', db='test', charset='utf8') cursor = con.cursor() sql = "select * from user" cursor.execute(sql) results = cursor.fetchmany(5) users = [] data = {} for r in results: user = {} user['id'] = r[0] user['name'] = r[1] user['age'] = r[2] user['tel'] = r[3] user['address'] = r[4] users.append(user) data['code'] = 0 data['users'] = users jsonStr = json.dumps(data) cursor.close() con.close() return jsonStr except MySQLdb.Error, e: print "Mysql Error %d: %s" % (e.args[0], e.args[1]) 以上这篇python查询mysql,返回json的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持码农之家。 ……

    <
    1
    >

    Copyright 2018-2020 www.xz577.com 码农之家

    版权投诉 / 书籍推广 / 赞助:520161757@qq.com