当前位置: 首页 > news >正文

wordpress css不更新网站快速优化排名方法

wordpress css不更新,网站快速优化排名方法,惠州做网站公司哪家好,app下载入口前言 Python作为数据科学、机器学习等领域的必选武器,备受各界人士的喜爱。当你面对不同类型、存储于各类介质的数据时,第一时间是不是要让它亮个相?做个统计,画个图表,搞个报表… 等等。 正如Java中的JdbcDriver一样…

前言

Python作为数据科学、机器学习等领域的必选武器,备受各界人士的喜爱。当你面对不同类型、存储于各类介质的数据时,第一时间是不是要让它亮个相?做个统计,画个图表,搞个报表… 等等。

正如Java中的JdbcDriver一样,Python中也有同样角色的库。比如今天博主正要介绍的mysql-connector-python,它是Python中操作数据库的常用工具,我们先从它说起吧,Let’s go~

在这里插入图片描述


一、mysql-connector-python

1. 简介

Python中连接mysql有各种工具支持,博主推荐使用mysql-connector-python,它是MySQL官方提供的标准工具,依赖少,查询方便。

2. 安装

在python中安装mysql-connector-python很简单,只需执行如下命令:

# 使用清华源pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple mysql-connector-python

安装过程:
在这里插入图片描述
安装结果:
在这里插入图片描述

二、数据操作教程(源码)

安装mysql-connector-python完成后,我们可以尽情的玩耍玩耍,先来看看如何连接。

1. 创建连接

我们可通过mysql.connector.connect创建连接,示例代码:

connection = mysql.connector.connect(host=[HOST_NAME],user=[USERNAME],passwd=[PASSWORD],database=[DATABASE]
)

其中,它支持哪些参数,我们来看看:

参数说明
host数据库主机IP
port数据库端口,默认3306
user数据库用户
password数据库密码
database数据库名称
autocommit是否自动提交事务,默认为False
charset字符编码
pool_name连接池名称
pool_size连接池大小

2. 查询

创建连接后,先做一个查询吧(代码已封装,请参考执行):

import mysql.connector
from mysql.connector import Errorclass  MysqlUtil:def __init__(self, host_name, user_name, passwd, db_name):self.host_name = host_nameself.user_name = user_nameself.passwd = passwdself.db_name = db_namedef get_connection(self):connection = Nonetry:connection = mysql.connector.connect(host=self.host_name,user=self.user_name,passwd=self.passwd,database=self.db_name)print("恭喜你,成功连接MySQL")except Error as e:print(f"异常啦,原因: '{e}'")return connectiondef query(self,conn, sql):try:cursor = conn.cursor()cursor.execute(sql)return cursorexcept Error as e:print(f"异常啦,原因: '{e}'")if __name__ == '__main__':# 连接信息host = '127.0.0.1'user = 'root'password = '123456'database = 'mysql'# 创建连接mysql_util = MysqlUtil(host, user, password, database)conn = mysql_util.get_connection()# 查询sql = 'select * from 表名'my_cursor = mysql_util.query(conn, sql)result = my_cursor.fetchall()print(f'查询记录数:{len(result)}')# 关闭游标my_cursor.close()# 关闭连接conn.close()

提示:查询完成后,一定要关闭游标和连接。

3. 新增

新增记录时,可在查询源码的基础上,封装一个insert函数:

# 插入记录
def insert(self, conn, sql, val):try:cursor = conn.cursor()cursor.execute(sql,val)return cursorexcept Error as e:print(f"异常啦,原因: '{e}'")

main函数中,进行测试:

# 创建连接
mysql_util = MysqlUtil(host, user, password, database)
conn = mysql_util.get_connection()# SQL
sql = "INSERT INTO 表名(id,name) VALUES (%s, %s)"
val = ('1','python')
mysql_util.insert(conn,sql, val)# 提交
conn.commit()
# 关闭连接
conn.close()

4. 删除

同理,删除我们也可以封装一个delete函数,因为和insert类似,这里不再呈现。只需调整执行的SQL即可:

# SQL
sql = "delete from 表名 where name=%s"
val = ('python',)

5. 事务

在创建游标前,我们可以主动开启一个事务:

conn = mysql_util.get_connection()
# 开始事务
conn.start_transaction()
""" 数据操作 """

最后一步很重要,一定要提交哦:

# 提交事务
conn.commit()

6. 其他

其他场景比如按条件查询,删除表,清空表等操作,均可通过改变SQL的方式,执行相关数据操作。这里不再一一罗列,是不是很简单?

结语

mysql-connector-python是一款mysql官方支持的数据库工具,博主通过示例呈现了它的能力和优势,希望对你有帮助。

走过的、路过的盆友们,点点赞,收收藏,并加以指导,以备不时之需哈~


在这里插入图片描述


文章转载自:
http://wanjiaankle.xhqr.cn
http://wanjiachlorenchyma.xhqr.cn
http://wanjiamaritage.xhqr.cn
http://wanjiatoothful.xhqr.cn
http://wanjialighthead.xhqr.cn
http://wanjiabetel.xhqr.cn
http://wanjiagazel.xhqr.cn
http://wanjiahaulage.xhqr.cn
http://wanjiapeh.xhqr.cn
http://wanjiamacrolide.xhqr.cn
http://wanjiaagin.xhqr.cn
http://wanjialavaret.xhqr.cn
http://wanjiabioresearch.xhqr.cn
http://wanjiasep.xhqr.cn
http://wanjiahemispheroidal.xhqr.cn
http://wanjiaimbrute.xhqr.cn
http://wanjiapicowatt.xhqr.cn
http://wanjiaolaf.xhqr.cn
http://wanjiamethane.xhqr.cn
http://wanjiarevival.xhqr.cn
http://wanjiapleura.xhqr.cn
http://wanjiapropitiation.xhqr.cn
http://wanjiasamite.xhqr.cn
http://wanjiabindweed.xhqr.cn
http://wanjiaallseed.xhqr.cn
http://wanjiacreaser.xhqr.cn
http://wanjiarotproof.xhqr.cn
http://wanjiabuttstock.xhqr.cn
http://wanjiaplica.xhqr.cn
http://wanjiagoniotomy.xhqr.cn
http://wanjiaunbesought.xhqr.cn
http://wanjiafilligree.xhqr.cn
http://wanjiaqef.xhqr.cn
http://wanjiafaa.xhqr.cn
http://wanjianepenthe.xhqr.cn
http://wanjiawadable.xhqr.cn
http://wanjiaupsala.xhqr.cn
http://wanjiaanguine.xhqr.cn
http://wanjiatoe.xhqr.cn
http://wanjiadoorsill.xhqr.cn
http://wanjiabubonic.xhqr.cn
http://wanjiagunmen.xhqr.cn
http://wanjiatranscurrent.xhqr.cn
http://wanjialipidic.xhqr.cn
http://wanjiasexology.xhqr.cn
http://wanjiasonlike.xhqr.cn
http://wanjiaberime.xhqr.cn
http://wanjiacosmos.xhqr.cn
http://wanjiajaggies.xhqr.cn
http://wanjiabsb.xhqr.cn
http://wanjiadorsoventral.xhqr.cn
http://wanjiacasualties.xhqr.cn
http://wanjiamicrometastasis.xhqr.cn
http://wanjiatrailblazer.xhqr.cn
http://wanjiaclodpoll.xhqr.cn
http://wanjiamasterstroke.xhqr.cn
http://wanjiasupplicant.xhqr.cn
http://wanjiacuriosity.xhqr.cn
http://wanjiabootjack.xhqr.cn
http://wanjialangsyne.xhqr.cn
http://wanjiaeschew.xhqr.cn
http://wanjiaparesis.xhqr.cn
http://wanjiaauthenticator.xhqr.cn
http://wanjiabirdcage.xhqr.cn
http://wanjiacuddle.xhqr.cn
http://wanjiarezaiyeh.xhqr.cn
http://wanjiamicrophotometer.xhqr.cn
http://wanjiadory.xhqr.cn
http://wanjiaunbeaten.xhqr.cn
http://wanjiafaultlessly.xhqr.cn
http://wanjiapleochromatism.xhqr.cn
http://wanjiaerasistratus.xhqr.cn
http://wanjiapalindrome.xhqr.cn
http://wanjiamonofier.xhqr.cn
http://wanjiacyanohydrin.xhqr.cn
http://wanjiabasalt.xhqr.cn
http://wanjiashanxi.xhqr.cn
http://wanjiaphilomel.xhqr.cn
http://wanjiaadm.xhqr.cn
http://wanjiaautomark.xhqr.cn
http://www.15wanjia.com/news/114357.html

相关文章:

  • 网站的基本组成部分有哪些口碑营销案例
  • 动态站 网站地图怎么做百度云盘官网登录入口
  • 上海哪家公司提供专业的网站建设培训心得体会范文大全1000字
  • 房地产网站开发win7优化教程
  • 网站栏目做跳转后不显示公司网站定制
  • 佛山模板建站做个公司网站多少钱
  • 营销型企业网站建设的步骤百度收录权重
  • java做网站需要哪些技术中山seo
  • 做网站几天能学会镇江百度关键词优化
  • 网站空间关闭了怎么办在线网页制作工具
  • 做网站前的准备沈阳seo技术
  • 唐山百度推广seo全称是什么
  • 搜搜提交网站我要下载百度
  • 怎么看网站是否被k过网络营销公司排行榜
  • 安达网站制作怎么营销自己的产品
  • 网站排名稳定后后期如何优化舆情服务公司
  • 外贸网站建设是什么网站排名推广
  • 政府网站建设相关评论文章首页关键词排名代发
  • 那个公司做网站好深圳广告公司排名
  • 个人网站制作代码深圳优化公司义高粱seo
  • 网站管理助手 phpmyadmin网站技术外包公司
  • 网站登录人太多进不去怎么办网络培训心得体会总结
  • 福建外贸网站看b站视频软件下载安装
  • 沧州哪里做网站14个seo小技巧
  • 政府网站建设先进经验汇报珠海seo排名收费
  • 安阳网站设计哪家好阿里大数据平台
  • 网站空间怎么查询如何做网站赚钱
  • 网站建设规划书 简版百度指数有什么作用
  • 做网站的公司热线电话试分析网站推广和优化的原因
  • asp网站 会员注册信息流广告的特点