python mysql 连接

本文介绍如何在PyCharm中配置并使用MySQL数据库,包括设置项目支持MySQL、安装pymysql模块以及通过pip安装mysqlclient的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

python mysql 连接

# 1 pycharm安装pymysql

setting project 添加mysql库支持
DATABASES = {
'default':{
'ENGINE':'django.db.backends.mysql',
'NAME':'django', //库名
'HOST':'127.0.0.1', //连接地址,本地也可以写成localhost
'PORT':3306,
'USER':'root',
'PASSWORD':'admin'
}
}

2 安装mysqlcilent

点击打开网页
这个网站提供了很多python库,ctrl + f 搜索 mysqlclient点击打开是这个样子的

Mysqlclient, a fork of the MySQL-python interface for the MySQL database.
    mysqlclient‑1.3.12‑cp27‑cp27m‑win32.whl
    mysqlclient‑1.3.12‑cp27‑cp27m‑win_amd64.whl
    mysqlclient‑1.3.12‑cp34‑cp34m‑win32.whl
    mysqlclient‑1.3.12‑cp34‑cp34m‑win_amd64.whl
    mysqlclient‑1.3.12‑cp35‑cp35m‑win32.whl
    mysqlclient‑1.3.12‑cp35‑cp35m‑win_amd64.whl
    mysqlclient‑1.3.12‑cp36‑cp36m‑win32.whl
    mysqlclient‑1.3.12‑cp36‑cp36m‑win_amd64.whl

选择适合的版本下载
- cp后面跟的是python版本,比如cp36代表python3.6
- amd64 表示win64位系统,跟处理器没有关系

下载完成后在下载目录右键命令窗口输入命令安装
- pip install mysqlclient‑1.3.12‑cp36‑cp36m‑win_amd64.whl
在pycharm控制台输入
pip install mysqlclient

Python链接MySQL驱动包,安装之后可以使用Python语言链接MySQL进行数据库操作 # mysqlclient [![Build Status](https://secure.travis-ci.org/PyMySQL/mysqlclient-python.png)](http://travis-ci.org/PyMySQL/mysqlclient-python) This is a fork of [MySQLdb1](https://github.com/farcepest/MySQLdb1). This project adds Python 3 support and bug fixes. I hope this fork is merged back to MySQLdb1 like distribute was merged back to setuptools. ## Install ### Prerequisites You may need to install the Python and MySQL development headers and libraries like so: `sudo apt-get install python-dev libmysqlclient-dev` # Debian / Ubuntu `sudo yum install python-devel mysql-devel` # Red Hat / CentOS On Windows, there are binary wheel you can install without MySQLConnector/C or MSVC. #### Note on Python 3 : if you are using python3 then you need to install python3-dev using the following command : `sudo apt-get install python3-dev` # debian / Ubuntu `sudo yum install python3-devel ` # Red Hat / CentOS `brew install mysql-connector-c` # macOS (Homebrew) ### Install from PyPI `pip install mysqlclient` NOTE: Wheels for Windows may be not released with source package. You should pin version in your `requirements.txt` to avoid trying to install newest source package. ### Install from source 1. Download source by `git clone` or [zipfile](https://github.com/PyMySQL/mysqlclient-python/archive/master.zip). 2. Customize `site.cfg` 3. `python setup.py install` ### Documentation Documentation is hosted on [Read The Docs](https://mysqlclient.readthedocs.io/)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值