尝试着用python连接mysql数据库!!!
由于python和mysql版本众多,本人只针对自己使用的版本负责;
python 3.5.2
mysql 8.0.x
操作系统 win10 64位
首先你得装好python和mysql数据库....
选择合适版本的python和mysql,分别安装,并且需要把各自的软件根目录,一般是在/bin之下的路径加入到系统目录中;
mysql初始化设置安装:
参考这个:
https://my.oschina.net/LinearLawX/blog/3064851
需要注意重新设置密码的问题!!!
python 需要安装pymysql
pip install PyMySQL
然后尝试以下代码(运行之前要保证mysql用户名、密码以及test_db这个数据库是存在的):
#-*-coding:utf-8-*- import pymysql as pq conn = pq.connect('localhost','root','root','test_db') cursor = conn.cursor() print(conn) print(cursor) cursor.close() conn.close()
大概是这样吧!