python数据库模块

  • 安装数据库
[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)

猜你喜欢

转载自www.cnblogs.com/t-ym/p/11826510.html
今日推荐