首页 > 数据库技术 > 详细

python数据库模块

时间:2019-11-13 12:37:35      阅读:88      评论:0      收藏:0      [点我收藏+]
  • 安装数据库
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum -y install MariaDB
systemctl restart mysql
systemctl enable mysqld
  • 配置数据库
mysql
> grant all privileges on *.* to root@‘%‘ identified by ‘root‘;
flush privileges;
> use mysql;
> select host,user,password from user;
exit
firewall-cmd --add-port=3306/tcp
firewall-cmd --add-port=3306/tcp --permanent
  • 连接数据库
import pymysql
db = pymysql.connect(host="192.168.200.12",user="root",
password="root",db="mysql",port=3306)
cusor = db.cursor() 
cursor.excute(‘select host,user,password from user‘) # cursor 是游标
#cursor.excute(‘create database class‘) #excute 执行
res = cursor.fetchall() #查询命令
res = cursor.fetchmany()
for result in res :
print(result)

 

python数据库模块

原文:https://www.cnblogs.com/t-ym/p/11826510.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!