现在的位置: 首页 > 综合 > 正文

python、mysql安装及连接

2018年04月30日 ⁄ 综合 ⁄ 共 1655字 ⁄ 字号 评论关闭

1.python是ubuntu自带的,版本号2.7

2.mysql安装

(1)从官网上下载linux下的mysql安装包mysql-5.6.14-linux-glibc2.5-i686.tar.gz

(2)拷贝到/usr/local,tar -xvf  mysql***.tar.gz

(3)添加mysql用户组, sudo gourpadd mysql,mkdir /home/mysql,为mysql账户建立文件夹

(4)添加mysql账户,sudo useradd -g mysql -d /home/mysql mysql

(5)建立解压目录的链接,简化名称 ln -s mysql***** mysql

(6)cd /usr/local/mysql, chown -R mysql . ,chgrp -R mysql ., 修改mysql文件夹的所属用户组和账户

(7)执行安装 ./scripts/mysql_install_db --user=mysql。 mysql -u root password '***'修改密码

(8)cp supprt-file/mysql.server /etc/init.d/mysql

问题:mysql start报错

修改报错文件路径的账户权限,具体忘记了

3.mysqldb安装

(1)下载安装包,解压缩

(2)执行sudo python setup.py build

问题:报错In file included from _mysql.c:29:
pymemcompat.h:
10:20:
error: Python.h: No such
file or directory
_mysql.c:
30:26:
error: structmember.h: No such 
file or directory
In 
file included from /usr/include/mysql/mysql.h:44from _mysql.c:40:
. . . _mysql.c:
2808:
warning: 
return type defaults
to 
'int' _mysql.c:
In function
'DL_EXPORT':
_mysql.c:
2808:
error: expected declaration specifiers before
'init_mysql' _mysql.c:2886:
error: expected 
'{' at
end of 
input error:
command 
'gcc'failed with exit
status

执行sudo apt-get install python-dev
(3)sudo python setup.py install
问题:mysql_config: not found
首先查找mysql_config的位置,使用find / -name mysql_config ,比如我的在/usr/local/mysql/bin/mysql_config
修改setup_posix.py文件,在26行:
mysql_config.path = "mysql_config" 修改为:
mysql_config.path = "/usr/local/mysql/bin/mysql_config"
修改完成后保存,再执行
python setup.py build
python setup.py install
python setup.py bdist_rpm

4.安装完成后,import MySQLdb报错

问题:File “MySQLdb/__init__.py”, line 19, in 
import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

ln -s /usr/local/mysql/lib/libmysqlclient.so.18
/usr/lib/libmysqlclient.so.18

全部完成

抱歉!评论已关闭.