Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connector/Python安装—使用Python连接MySQL #55

Open
johnnian opened this issue Nov 16, 2018 · 0 comments
Open

Connector/Python安装—使用Python连接MySQL #55

johnnian opened this issue Nov 16, 2018 · 0 comments

Comments

@johnnian
Copy link
Owner

johnnian commented Nov 16, 2018

说明

要使用Python操作MySQL,需要安装 Connector/Python,下面是具体的步骤

操作系统:Centos系列、OpenSUSE

Python版本:2.X系列(2.6.9及其以上)

参考网站:

准备步骤

1、shell支持中文

[root@359f34d1b4c6 ~]# vi ~/.bash_profile 
LANG=zh_CN.GB18030 
LANGUAGE=zh_CN.GB18030:zh_CN.GB2312:zh_CN 
export LANG LANGUAGE 
[root@359f34d1b4c6 ~]# . ~/.bash_profile 

2、安装依赖包-setuptools

可以选择下面两种方式安装:

A-安装pip

[root@359f34d1b4c6 ~]# yum -y install zlib*
[root@359f34d1b4c6 ~]# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
[root@359f34d1b4c6 ~]# python get-pip.py

参考: pip.pypa.io/en/stable/installing/

B-安装setuptools

CentOS:

# 1-下载python的setuptools
[root@359f34d1b4c6 ~] wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/python/SLE_11_SP2/x86_64/python-setuptools-2.1-37.1.x86_64.rpm
# 2-安装setuptools
[root@359f34d1b4c6 ~] rpm -ivh python-setuptools-2.1-37.1.x86_64.rpm

SUSE 11:

[root@359f34d1b4c6 ~] wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
[root@359f34d1b4c6 ~] tar zxvf setuptools-0.6c11.tar.gz
[root@359f34d1b4c6 ~] cd setuptools-0.6c11
[root@359f34d1b4c6 ~] python setup.py build
[root@359f34d1b4c6 ~] python setup.py install

安装Connector/Python

#1-下载Connector/Python:
[root@75d336b8c2cf ~]# wget cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-8.0.13.tar.gz

#2-解压与安装:
[root@75d336b8c2cf ~]# tar -zxvf mysql-connector-python-8.0.13.tar.gz
[root@75d336b8c2cf ~]# cd mysql-connector-python-8.0.13
[root@75d336b8c2cf mysql-connector-python-8.0.13]# python setup.py build
[root@75d336b8c2cf mysql-connector-python-8.0.13]# python setup.py install

# 备注:对于 CentOS,可以直接:python -m pip install mysql-connector 安装

#3-测试是否成功:如果没有报错,就说明成功!
[root@75d336b8c2cf ~]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant