美文网首页
mac python sql

mac python sql

作者: 梦开始的地方是海 | 来源:发表于2016-08-04 15:25 被阅读0次

1.更新pip
sudo pip install --upgrade pip
安装mysql-connector(三选一)
1).pip install mysql-connector-python-rf==2.1.3

2).brew install mysql-connector-c
pip install MySQL-python

3)brew install mysql(推荐这种)

2.安装后没设定初始密码,则需要进行设定后,才能进行数据库操作:

1)mysql -uroot 进入mysql操作
2)ALTER USER 'root'@'localhost'IDENTIFIED by '123'; 更改root密码为123
3)create database <dataname>; 创建数据库
4)use <dataname>;使用创建的数据库

3.连接sql时conn = pymysql.connect(host='127.0.0.1',user = 'root',password = '123',db = 'mysql',charset = 'utf8')
其中charset = 'utf8'必须加上,否则就要在sql中设置数据编码方式,以免出现乱码

相关文章

网友评论

      本文标题:mac python sql

      本文链接:https://www.haomeiwen.com/subject/sawcsttx.html