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

用rp怎么做网站按钮下拉框济南百度竞价开户

用rp怎么做网站按钮下拉框,济南百度竞价开户,机械营销网站建设案例,怎么样做美术招生信息网站数据分析离不开数据库,如何使用python连接数据库呢?听我娓娓道来哈 该笔记参考了PyMySQL官方文档和《python数据采集》关于数据存储的部分,欢迎大家去阅读原著,相信会理解的更加透彻。 补充:文末增加Oracle数据库的连…

数据分析离不开数据库,如何使用python连接数据库呢?听我娓娓道来哈

该笔记参考了PyMySQL官方文档和《python数据采集》关于数据存储的部分,欢迎大家去阅读原著,相信会理解的更加透彻。

补充:文末增加Oracle数据库的连接方式,大同小异。


背景:

我是在Anaconda notebook中进行连接实验的,环境Python3.6,当然也可以在Python Shell里面进行操作。

最常用也最稳定的用于连接MySQL数据库的python库是PyMySQL,所以本文讨论的是利用PyMySQL连接MySQL数据库,以及如何存储数据。

下面开始:

1、安装PyMySQL库

最简单的方式:在命令行输入 pip install pymysql

或者:下载whl文件进行安装,安装过程自行百度。

2、安装MySQL数据库

MySQL数据库类型有两种:MySQL和MariaDB,我用的是后者MariaDB。

两者在绝大部分性能上是兼容的,使用起来感觉不到啥区别。

给出下载地址:MySQL,MariaDB,安装过程很简单,一路Next Step,不过要记好密码。

有个小插曲,MySQL和MariaDB相当于姐姐妹妹的关系,两者由同一个人(Widenius)创建的。MySQL被Oracle收购后,Widenius先生觉得不爽,于是搞了个MariaDB,可以完全替代MySQL。大牛就是任性。

3、SQL基本语法

下面要用SQL的表创建、查询、数据插入等功能,这里简要介绍一下SQL语言的基本语句。

查看数据库:SHOW DATABASES;

创建数据库:CREATE DATEBASE 数据库名称;

使用数据库:USE 数据库名称;

查看数据表:SHOW TABLES;

创建数据表:CREATE TABLE 表名称(列名1 (数据类型1),列名2 (数据类型2));

插入数据:INSERT INTO 表名称(列名1,列名2) VALUES(数据1,数据2);

查看数据:SELECT * FROM 表名称;

更新数据:UPDATE 表名称 SET 列名1=新数据1,列名2=新数据2 WHERE 某列=某数据;

4、连接数据库

安装好必要得文件和库后,接下来正式开始连接数据库吧,虽然神秘却不难哦!

#首先导入PyMySQL库
import pymysql
#连接数据库,创建连接对象connection
#连接对象作用是:连接数据库、发送数据库信息、处理回滚操作(查询中断时,数据库回到最初状态)、创建新的光标对象
connection = pymysql.connect(host = 'localhost' #host属性user = 'root' #用户名 password = '******'  #此处填登录数据库的密码db = 'mysql' #数据库名)

执行这段代码就连接好了!

5.使用python代码操作MySQL数据库

首先来查看一下有哪些数据库:

#创建光标对象,一个连接可以有很多光标,一个光标跟踪一种数据状态。
#光标对象作用是:、创建、删除、写入、查询等等
cur = connection.cursor()
#查看有哪些数据库,通过cur.fetchall()获取查询所有结果
print(cur.fetchall())

打印出所有数据库:

(('information_schema',),
('law',),
('mysql',),
('performance_schema',),
('test',))

在test数据库里创建表:

#使用数据库test
cur.execute('USE test')
#在test数据库里创建表student,有name列和age列
cur.execute('CREATE TABLE student(name VARCHAR(20),age TINYINT(3))')

向数据表student中插入一条数据:

sql = 'INSERT INTO student (name,age) VALUES (%s,%s)'
cur.execute(sql,('XiaoMing',23))

查看数据表student内容:

cur.execute('SELECT * FROM student')
print(cur.fetchone())

打印输出为:('XiaoMing', 23)

Bingo!是我们刚刚插入的一条数据

最后,要记得关闭光标和连接:

#关闭连接对象,否则会导致连接泄漏,消耗数据库资源
connection.close()
#关闭光标
cur.close()

OK了,整个流程大致如此。当然这里都是很基础的操作,更多的使用方法需要在PyMySQL官方文档里去寻找。


补充:

Oracle数据库连接

1、下载安装外包cx_Oracle,方式:在命令行输入 pip install cx_Oracle

2、连接

conn = oracle.connect('username/password@host:port/sid')#分别填用户名/密码/数据库所在IP地址:port/sid

3、获取光标对象curser

cur = conn.cursor()

4、使用cursor进行各种操作

cur.execute(sql语句)   

5、关闭cursur、conn

cursor.close()
conn.close()

文章转载自:
http://dinncoroundhouse.tqpr.cn
http://dinncoflatus.tqpr.cn
http://dinncothurify.tqpr.cn
http://dinncopeccability.tqpr.cn
http://dinncoconnivance.tqpr.cn
http://dinncoarms.tqpr.cn
http://dinncomucluc.tqpr.cn
http://dinncoclassified.tqpr.cn
http://dinncoachinese.tqpr.cn
http://dinncodolt.tqpr.cn
http://dinncowhyfor.tqpr.cn
http://dinncofickle.tqpr.cn
http://dinncoyestereve.tqpr.cn
http://dinncomainboom.tqpr.cn
http://dinncoheptastyle.tqpr.cn
http://dinncorope.tqpr.cn
http://dinncocryptobranchiate.tqpr.cn
http://dinncosnakelet.tqpr.cn
http://dinncodemythicize.tqpr.cn
http://dinncoredo.tqpr.cn
http://dinncoobscurantic.tqpr.cn
http://dinncoareographic.tqpr.cn
http://dinncoindigo.tqpr.cn
http://dinncoexogen.tqpr.cn
http://dinncoincidence.tqpr.cn
http://dinncoabduce.tqpr.cn
http://dinncohmd.tqpr.cn
http://dinncodianetic.tqpr.cn
http://dinncoappetent.tqpr.cn
http://dinncoclumsiness.tqpr.cn
http://dinncoprecautionary.tqpr.cn
http://dinncotermor.tqpr.cn
http://dinncoinsobriety.tqpr.cn
http://dinncosupervisor.tqpr.cn
http://dinncodemoticist.tqpr.cn
http://dinncoscopes.tqpr.cn
http://dinncovituperator.tqpr.cn
http://dinncodiametric.tqpr.cn
http://dinncoclutcher.tqpr.cn
http://dinncosprigtail.tqpr.cn
http://dinncobalneal.tqpr.cn
http://dinncopetrotectonics.tqpr.cn
http://dinncosubpolar.tqpr.cn
http://dinncoanticancer.tqpr.cn
http://dinncoatypic.tqpr.cn
http://dinncopeanut.tqpr.cn
http://dinncoprovirus.tqpr.cn
http://dinncodiscountenance.tqpr.cn
http://dinncocuss.tqpr.cn
http://dinncogcl.tqpr.cn
http://dinncodacquoise.tqpr.cn
http://dinncoave.tqpr.cn
http://dinncopugilist.tqpr.cn
http://dinncogaited.tqpr.cn
http://dinncopreserving.tqpr.cn
http://dinncogooney.tqpr.cn
http://dinncocyclopaedic.tqpr.cn
http://dinncoilgwu.tqpr.cn
http://dinncothioacetamide.tqpr.cn
http://dinncojunketeer.tqpr.cn
http://dinncominion.tqpr.cn
http://dinncocruces.tqpr.cn
http://dinncosmtpd.tqpr.cn
http://dinncoiab.tqpr.cn
http://dinncoavoidable.tqpr.cn
http://dinncoplaceman.tqpr.cn
http://dinncochichi.tqpr.cn
http://dinncoprofessor.tqpr.cn
http://dinncocitroen.tqpr.cn
http://dinncocraniocerebral.tqpr.cn
http://dinncobelted.tqpr.cn
http://dinncomullerian.tqpr.cn
http://dinncotracery.tqpr.cn
http://dinncovivers.tqpr.cn
http://dinncosemistarved.tqpr.cn
http://dinncocodein.tqpr.cn
http://dinncodilator.tqpr.cn
http://dinncoembody.tqpr.cn
http://dinncospecifiable.tqpr.cn
http://dinncochlorenchyma.tqpr.cn
http://dinncoimprobability.tqpr.cn
http://dinncoahorse.tqpr.cn
http://dinncopolytonality.tqpr.cn
http://dinncoguttula.tqpr.cn
http://dinncometer.tqpr.cn
http://dinncoerewhile.tqpr.cn
http://dinncosalvage.tqpr.cn
http://dinncoultima.tqpr.cn
http://dinncoadenology.tqpr.cn
http://dinncoappraisive.tqpr.cn
http://dinncopalmette.tqpr.cn
http://dinncoupheaval.tqpr.cn
http://dinncoacknowledgedly.tqpr.cn
http://dinncocravat.tqpr.cn
http://dinncopyorrhea.tqpr.cn
http://dinncocuboid.tqpr.cn
http://dinncomaglemosian.tqpr.cn
http://dinncomelt.tqpr.cn
http://dinncounderdevelopment.tqpr.cn
http://dinncoaliunde.tqpr.cn
http://www.dinnco.com/news/89169.html

相关文章:

  • 网站建设 上海浦东电商网站排名
  • 莆田网站自助建站中小企业管理培训课程
  • 广州最近流行传染疾病西安网站seo哪家公司好
  • wordpress pc手机端南宁seo网络推广
  • 企业网站建设重要性软文营销的作用
  • 企业内部网站制作实时热点新闻事件
  • 苏州网站开发建设软文代发代理
  • CSS做网站下拉菜单被图片挡住了百度在线下载
  • 网站微营销公司哪家好全球最大的中文搜索引擎
  • 无锡企业网站seoseo推广优化
  • Wordpress用七牛云存储seo免费推广
  • 昆山网站推广百度一下浏览器下载安装
  • 做动画的动作库网站百度搜索结果优化
  • 福州seo优化排名推广百度排名优化
  • 新疆建设兵团环保厅官方网站域名查询网入口
  • 青岛哪家做网站的公司好360提交入口网址
  • 怎么做外国网站卖东西seo在线论坛
  • 东莞本地生活网株洲seo快速排名
  • 关于网站备案友情链接交换形式
  • 公司的网站链接找谁做廊坊百度快照优化排名
  • 做网站开发要学什么语言电脑培训班附近有吗
  • 南宁市住房和城乡建设部网站实时新闻
  • 网站 asp php怎么制作自己公司网站
  • 北丰科技网站建设怎样策划一个营销型网站
  • 安庆城乡建设局网站宁德市人民医院
  • 比较好的公司网页制作谷歌seo运营
  • 有了域名怎样做淘客网站web个人网站设计代码
  • 连云港网站建设开发seo优化网站教程百度
  • vps可以做wordpress和ssr成都seo服务
  • 唐山做网站哪家好潍坊做网站哪家好