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

bl 做视频网站专业营销策划团队

bl 做视频网站,专业营销策划团队,网站渗透入侵全部教程,威海seo网站推广师从黑马程序员 数据库介绍 数据库就是存储数据的库 数据组织:库->表->数据 数据库和SQL的关系 MySQL的基础命令 SQL基础 SQL语言的分类 SQL的语法特征 DDL-库管理 show DATABASES;use sys;SELECT database();CREATE DATABASE test CHARSET utf-8;SHOW D…

师从黑马程序员

数据库介绍

数据库就是存储数据的库

数据组织:库->表->数据

数据库和SQL的关系

MySQL的基础命令

 

SQL基础

SQL语言的分类

SQL的语法特征

DDL-库管理

show DATABASES;use sys;SELECT database();CREATE DATABASE test CHARSET utf-8;SHOW DATABASES;-- drop DATABASE test01;

DDL-表管理

use students;show TABLES;CREATE TABLE student(id int,name VARCHAR(10),age int 
);drop table student;

DML-数据操作

数据插入-INSERT

create table student(id int,name VARCHAR(10),age int
);insert into student(id) VALUES(1),(2),(3);# 等价于
-- insert into student(id) VALUES(1);
-- insert into student(id) VALUES(1);
-- insert into student(id) VALUES(1);
insert into student(id,name,age) VALUES(4,'周杰伦',31),(5,'领军解',33);

数据删除-DELETE

DELETE from student WHERE id =4;

数据更新-Update

UPDATE student set name ='张学友' where id ='5';

注:字符串的值,出现在SQL语句中,必须要用单引号

DQL-数据查询

基础数据查询

select id,name,age from student;select * from student;SELECT * from student where age>20;
select * from student where name ='张学友';

分组聚合

select id,avg(age) from student group by id;

-- 在非聚合函数中,GROUP BY 后出现什么,select 才能出现什么,但对像聚合函数avg()不适用

select id,avg(age),sum(age),min(age),max(age),count(*) from student group by id;

排序分页

结果排序

 

结果分页限制

select * from student where age >20 order by age ASC;
-- asc升序  de 降序

select * from student limit 5;
-- 只查询5条数据SELECT * from student LIMIT 10,5;
-- 6跳过前10条数据,然后查询5条数据-- 可以和其他语句结合
select age,count(*) from student where age>20 group by age ORDER BY age LIMIT 3;

Python操作MySQL语句

创建到MySQL的数据库链接

from pymysql import Connection#构建到MySQL数据库的链接
conn=Connection(host="localhost",   #主机名port=3306,  #端口user="root",    #账户password="5863AXzy@"    #密码
)# print(conn.get_server_info())#打印出数据库的基本信息#执行非查询性质SQL
# cursor=conn.cursor()    #获取游标对象
# #选择数据库
# conn.select_db("students")
# #执行sql          #传入sql语句
# cursor.execute("create table students_pymysql(id int);")#创建一个在students库下的students_pymysql表    #分号可不写#执行查询性质的SQL
cursor=conn.cursor()    #获取游标对象
#选择数据库
conn.select_db("students")
#执行sql          #传入sql语句
cursor.execute("select * from student")
#拿到上述语句的结果
results=cursor.fetchall()   #生成的是元组
for r in results:print(r)
#关闭链接
conn.close()

commit-提交

from pymysql import Connection#构建到MySQL数据库的链接
conn=Connection(host="localhost",   #主机名port=3306,  #端口user="root",    #账户password="5863AXzy@"    #密码
)#执行查询性质的SQL
cursor=conn.cursor()    #获取游标对象
#选择数据库
conn.select_db("students")
#执行sql          #传入sql语句
cursor.execute("insert into student values(1,'张学友',23)")
#通过commit确认
conn.commit()
#关闭链接
conn.close()

自动commit

from pymysql import Connection#构建到MySQL数据库的链接
conn=Connection(host="localhost",   #主机名port=3306,  #端口user="root",    #账户password="5863AXzy@",    #密码autocommit=True #自动提交
)#执行查询性质的SQL
cursor=conn.cursor()    #获取游标对象
#选择数据库
conn.select_db("students")
#执行sql          #传入sql语句
cursor.execute("insert into student values(1,'林俊杰',23)")#关闭链接
conn.close()

综合案例

DDL定义

"""
SQL 综合案例,读取文件,写入MySQL
"""
from file_define import  TextFileReader, JsonFileReader
from data_define import Record
from pymysql import Connectiontext_file_reader = TextFileReader("D:/2011年1月销售数据.txt")
json_file_reader = JsonFileReader("D:/2011年2月销售数据JSON.txt")jan_data: list[Record] = text_file_reader.read_data()
feb_data: list[Record] = json_file_reader.read_data()
# 将2个月份的数据合并为1个list来存储
all_data: list[Record] = jan_data + feb_data#构建MySQL链接对象
conn=Connection(host="localhost",port=3306,user="root",password="5863AXzy@",autocommit=True
)
#获得游标对象
cursor=conn.cursor()
#选择数据库
conn.select_db("py_sql")
#组织SQL语句
for record in all_data:sql = "INSERT INTO orders(order_date, order_id, money, province) VALUES (%s, %s, %s, %s)"cursor.execute(sql, (record.date, record.order_id, record.money, record.province))conn.close()

若有侵权,请联系作者

http://www.zhongyajixie.com/news/59550.html

相关文章:

  • wordpress弹出层插件重庆百度推广seo
  • 做网站月入100万黑马培训是正规学校吗
  • 泰安公司网站建设价格查询推广赚钱的项目
  • 抚州做网站公司哪家好北京百度seo点击器
  • php美食网站开发的意义seo店铺描述例子
  • 艺术创意设计抖音搜索排名优化
  • 想注册一个做网站的公司好搜索关键词查询工具
  • java做软件的网站全网营销软件
  • 网站建设设计维片怎么写网站
  • 微信功能定制开发公众号排名优化软件
  • 全球旅游网站排名seo外包靠谱
  • 东莞个人网站设计百度网页pc版登录
  • 沈阳市疫情防控最新通告百度seo优化哪家好
  • 济南卓远网站建设免费友情链接网站
  • 珠海市网站建设的公司信息流优化师简历怎么写
  • 做任务挣钱的网站聚网络营销与直播电商就业前景
  • 大连建设工程信息网下载中心武汉网站优化公司
  • 常见的网站建设类型都有哪些方面职业技能培训学校
  • 深圳建站定制公司seo最新
  • 上海网站排名公司百度人工客服24小时电话
  • 正规的网站建设seo推广培训班
  • php怎样做网站谷歌引擎搜索
  • 软件app下载大全如何进行搜索引擎优化
  • 爱情动作片做网站小红书广告投放平台
  • 网站建设的规划和流程百度代运营公司
  • wordpress 编辑器表情插件独立站seo优化
  • 临沂做网站企业中国最新新闻
  • 制造行业网站建设企业文化案例
  • 做直销网站的公司竞价推广账户竞价托管收费
  • 网站规划与网站建设百度扫一扫入口