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

网站开发项目报价单建设网站的合约

网站开发项目报价单,建设网站的合约,wordpress斗图,PHP 网站搜索怎么做文章目录 MySQL终端命令1. 进入mysql2. 创建数据库3. 选择数据库4. 创建数据表1. 主键约束2. 外键约束3. 非空约束4. 唯一约束5. 使用默认约束6. 设置id为自增列 5. 查看数据表6. 修改数据表1. 修改表名2. 修改表的字段类型3. 修改表的字段名4. 为表添加字段5. 删除字段6. 调整… 文章目录 MySQL终端命令1. 进入mysql2. 创建数据库3. 选择数据库4. 创建数据表1. 主键约束2. 外键约束3. 非空约束4. 唯一约束5. 使用默认约束6. 设置id为自增列 5. 查看数据表6. 修改数据表1. 修改表名2. 修改表的字段类型3. 修改表的字段名4. 为表添加字段5. 删除字段6. 调整字段的位置7. 删除表的外键约束8. 删除数据表 7. 数据表的操作1. 新增数据2. 查询数据3. 修改数据4. 删除数据5. replace Python操作MySQL1. 连接数据库2. 创建表3. 插入数据4. 查询数据5. 更新数据6. 删除数据 MySQL终端命令 1. 进入mysql winr输入cmd进入终端 输入: mysql -u root -p再输入密码进入mysql 2. 创建数据库 输入注意语句后面一定要加“ ; ” create database test;创建好后查看数据库 show databases;3. 选择数据库 输入 use test;进入test数据库。 4. 创建数据表 1. 主键约束 输入 create table example1 (id int(3),name varchar(20),age int(3),primary key(id, name));2. 外键约束 create table example2(id int primary key, name varchar(20));create table example2sub(id int primary key, name varchar(20), age int, c_id int, constraint p_c_id foreign key(c_id) references example2(id));p_c_id是外键约束的名字c_id是添加了外键约束的列id是父表中定义的主键列 3. 非空约束 create table example3(id int, name varchar(20) not null);4. 唯一约束 create table example4(id int unique, name varchar(20));5. 使用默认约束 create table example5(id int, name varchar(20) default hahaha);6. 设置id为自增列 create table example6(id int primary key auto_increment, name varchar(20));5. 查看数据表 先选择数据库再查看该数据库的表 use test;show tables;查看表中各个列的定义 desc example4;6. 修改数据表 1. 修改表名 alter table example1 rename my_example1;2. 修改表的字段类型 alter table my_example1 modify name varchar(55);3. 修改表的字段名 alter table my_example1 change name my_name varchar(55);4. 为表添加字段 alter table my_example1 add column gender varchar(2) not null;5. 删除字段 alter table my_example1 drop column age;6. 调整字段的位置 将my_example1表中的my_name改为第一列 alter table my_example1 modify my_name varchar(55) first;将id调整到gender后 alter table my_example1 id int after gender;7. 删除表的外键约束 alter table example2sub drop foreign key p_c_id;8. 删除数据表 drop table example4, example5, example6;7. 数据表的操作 1. 新增数据 create table user(id int primary key auto_increment, name varchar(100), age int, phone_num varchar(20));insert into user(name, age, phone_num) values(xiaoli, 21, 111), (qiansan, 18, 222), (zhangsan, 30, 333);2. 查询数据 查询全部数据 select * from user;查询年龄大于20的用户 select name, age from user where age 20;3. 修改数据 将用户id为1的年龄更新为22 update user set age 22 where id 1;4. 删除数据 删除年龄在25以上的用户 delete from user where age 25;5. replace 如果表中存在相同主键的数据replace的作用相当于修改操作否则就是插入操作 select * from user;replace into user(id, name, age, phone_num) values(1, xiaoli, 21, 444), (2, qiansan, 18, 888), (3, zhangsan, 30, 999);select * from user;Python操作MySQL 1. 连接数据库 数据库的访问是通过连接对象来实现的。程序模块中必须提供连接对象构造函数。 import pymysql# connect是连接对象构造函数 # db是connect对象实例 db pymysql.connect(# 连接的数据库服务器主机名默认为本地主机(localhost)host localhost, # 连接数据库的用户名默认为当前用户user root,# 连接密码password 020202ly,# 连接的数据库名database testmysql, )# 创建一个游标对象 cursor db.cursor()cursor.execute(select version())# fetchone()从查询结果中获取下一行数据返回值为一个值的序列如果没有更多数据则返回None。 # 通过游标获取sql语句执行的结果。如果没有下面的代码则执行python代码并不能看到在MySQL中执行的结果。 result cursor.fetchone()print(result)# 关闭游标 cursor.close()# 关闭数据连接 db.close()若程序成功执行则会打印MySQL的版本。 2. 创建表 import pymysqldb pymysql.connect(host localhost,user root,password 020202ly,database testmysql,charset utf8 )cursor db.cursor()sql create table example(id int not null auto_increment,name varchar(45),age int null,primary key(id)) # 运行sql语句创建数据表example cursor.execute(sql)# 查询创建的新表的结构 cursor.execute(desc example) # fetchall()从查询结果中获取结果的所有行数据返回值包含序列的序列。 result cursor.fetchall()print(result)cursor.close()db.close()执行结果 使用pprint.pprint(result)打印出来的结果如下 可以看到使用pprint打印的结果可读性更强看着更舒服。 pprint也是python中的一个打印模块在使用前需要导入包。pprint()的作用也就是使打印出来的数据结构更加完整每行为一个数据结构更加方便阅读打印输出结果。 3. 插入数据 需要注意的是在execute后需要调用commit方法提交对数据的修改否则数据并不会真的插入到数据库中。 import pymysqldb pymysql.connect(host localhost,user root,password 020202ly,database testmysql,charset utf8 )cursor db.cursor()sql insert into example(id, name, age) values(1, 小明, 20), (2, 小红, 40) # 运行sql语句创建数据表example try:cursor.execute(sql)db.commit()print(数据提交成功) except Exception as e:# 调用此方法将导致数据库回滚到事事务开始时的状态。# 关闭数据库连接之前没有明确调用commit()提交数据更新将导致一个隐含的回滚动作rollback()被执行。db.rollback()cursor.close() db.close()4. 查询数据 用fetchone()方法返回一行数据用fetchall()方法返回多行数据。 import pymysql import pprint db pymysql.connect(host localhost,user root,password 020202ly,database testmysql,charset utf8 )cursor db.cursor()cursor.execute(select * from example)# fetchone方法 result1 cursor.fetchone() print(fetchone: ) pprint.pprint(result1)# 在第一次查询获取数据后一定要再执行一次查询语句因为上面fetchone获取了一条数据游标向后移动就只剩一条数据了。 cursor.execute(select * from example)# fetchall方法 result2 cursor.fetchall() print(fetchall: ) pprint.pprint(result2)cursor.close() db.close()5. 更新数据 更新操作和插入操作类似在修改完成后需要调用commit方法提交修改。 import pymysql import pprint db pymysql.connect(host localhost,user root,password 020202ly,database testmysql,charset utf8 )cursor db.cursor()cursor.execute(select * from example)# fetchone方法 result cursor.fetchall() print(更新前) pprint.pprint(result)cursor.execute(update example set age 30 where id 2)cursor.execute(select * from example)# fetchall方法 result cursor.fetchall() print(更新后) pprint.pprint(result)cursor.close() db.close()6. 删除数据 删除数据操作完后也需要调用commit方法提交 import pymysql import pprint db pymysql.connect(host localhost,user root,password 020202ly,database testmysql,charset utf8 )cursor db.cursor()cursor.execute(select * from example) result cursor.fetchall() print(删除前) pprint.pprint(result)cursor.execute(delete from example where id 2) cursor.execute(select * from example) result cursor.fetchall() print(删除后) pprint.pprint(result)cursor.close() db.close()
http://www.dnsts.com.cn/news/147063.html

相关文章:

  • 网站头部ps购物网站的建设时间
  • 网站做3儿童车开场动画青海住房与城乡建设厅网站
  • 鲜花店网站建设的规模设想seo培训优化课程
  • 企业网站建设要多虚拟电脑主机平台
  • 微网站首页佛山做企业网站
  • 腾讯云网站备案流程wordpress添加支付
  • 深圳网站设计优刻技术外包网站
  • 建设部门户网站条例免费下载公司开发个网站有哪些
  • 紫金网站制作哪个网站教做西餐
  • 做h5场景的网站官方传奇游戏
  • 自己用模板做网站陕西省门户网站建设政策
  • 唐山哪个公司做网站网站建设费用用
  • 设计云网站wordpress购买按钮插件
  • php搭建一个简单的网站phpnow 安装wordpress
  • 网站开发未来发展趋势广州 海珠 建网站
  • wordpress仿站容易被收录不dw网站指向邮箱超链接怎么做
  • 网站访问很慢企业网站建设时优化关键词的问题
  • 深圳招聘一般在哪个网站重要的龙岗网站建设
  • 息壤网站打不开了网站建设公司信科网络
  • 淘宝客优惠券网站建设教程外包公司
  • 天津网站建设排名开发公司起名
  • 网站建设_秀米排版编辑器 wordpress
  • 京东网站的建设与发展现状中国新闻社归哪个部门管
  • 网站建设产品话术新乡网站制作
  • 互联网金融网站设计做网站什么字体比较好看
  • 网站建设专家价格中国建设电工网站
  • 杭州公司建站模板地税局内网网站建设
  • 唐山网站从哪里找制作商城版网站开发
  • 用h5做的网站做网站荣耀体验服官网
  • 北京网站设计公司兴田德润放心淘宝客推广网站怎么做