mysql5.5增删改查


前言

最早MySQL数据库,瑞典AB公司开发的一款开源型的关系型数据库。随着时间的推移,瑞典AB公司把MySQL数据库转让给Sun公司,后来,Sun公司经营不善,又把MySQL数据库转让给甲骨文公司。
MySQL软件提供了十分快速的多线程、多用户、牢靠的SQL(结构化查询语言)数据库服务器。 MySQL服务器定位于任务关键型、重负荷生产系统,并能嵌入在大量部署的软件中。MySQL是MySQL AB的注册商标。MySQL软件采用双许可方式。用户可根据GNU通用公共许可(http://www.fsf.org/licenses/)条款,将MySQL软件作为开放源码产品使用,或从MySQL AB公司购买标准的商业许可证。关于我方许可策略的更多信息,请参见http://www.mysql.com/company/legal/licensing/
数据库基础->数据表->对数据进行增删改查操作


一、mysql5.5

mysql5.5下载安装的教程有很多,此处不再赘述。

二、命令

1.创建数据库

数据库命令:

//创建数据库
create database choose;
//creat database + 数据库名

//查看数据库
show databases;
show create database choose;

//选择数据库
use choose;
select database();

//打开数据库,\G表示竖排
select * from user\G;

//删除数据库
drop database choose;

2.表

代码如下(示例):

//选择数据库
use choose;
//创建表
create table anima(id int(4) primary key auto_increment,name varchar(20) not null,kunds varchar(8) not null,legs int(4),behavior varchar(50));
//备份表anima到anima1(anima1此前不存在)
create table anima1 link anima;
//将behavior字段数据类型改为varchar(30),且保留非空约束。
alter table anima1 modify name varchar(30) not null;

alter table anima1 add fur varchar(10);

alter table anima1 drop legs;

alter table anima1 engine=MyISAM;

mysql> create table stu(num int,name varchar(5),grade int);
Query OK, 0 rows affected (0.04 sec)

mysql> insert into stu values(1,'a',80);
Query OK, 1 row affected (0.01 sec)

mysql> select *from stu;
+------+------+-------+
| num  | name | grade |
+------+------+-------+
|    1 | a    |    80 |
+------+------+-------+
1 row in set (0.00 sec)

mysql> insert into stu(num,name) values(2,'b');
Query OK, 1 row affected (0.01 sec)

mysql> select *from stu;
+------+------+-------+
| num  | name | grade |
+------+------+-------+
|    1 | a    |    80 |
|    2 | b    |  NULL |
+------+------+-------+
2 rows in set (0.00 sec)

mysql> insert into stu values(3,'c',70),(4,'d',60);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select *from stu;
+------+------+-------+
| num  | name | grade |
+------+------+-------+
|    1 | a    |    80 |
|    2 | b    |  NULL |
|    3 | c    |    70 |
|    4 | d    |    60 |
+------+------+-------+
4 rows in set (0.00 sec)

mysql> update stu set num=5;
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> select *from stu;
+------+------+-------+
| num  | name | grade |
+------+------+-------+
|    5 | a    |    80 |
|    5 | b    |  NULL |
|    5 | c    |    70 |
|    5 | d    |    60 |
+------+------+-------+
4 rows in set (0.00 sec)

mysql> update stu set num=6 where name='a';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select *from stu;
+------+------+-------+
| num  | name | grade |
+------+------+-------+
|    6 | a    |    80 |
|    5 | b    |  NULL |
|    5 | c    |    70 |
|    5 | d    |    60 |
+------+------+-------+
4 rows in set (0.00 sec)

mysql> delete from stu where grade>70;
Query OK, 2 rows affected (0.01 sec)

mysql> select *from stu;
+------+------+-------+
| num  | name | grade |
+------+------+-------+
|    5 | c    |    70 |
|    5 | d    |    60 |
+------+------+-------+
2 rows in set (0.00 sec)
insert into anima1 values('1','米老鼠','鼠类','4','夜间活动'),('2','蜈蚣','多足纲','40','用毒液杀死食物'),('3','加菲猫','猫类','4','好吃懒做'),('4','唐老鸭','家禽','2','叫个不停'),('5','肥猫','哺乳动物','4','吃和睡');

查select
select * from 数据表名称;select 字段(某一列) from 数据表名称;

聚合函数用于对一组值进行计算并返回一个汇总值,常用的聚合函数有 累加求和sum()函数、平均值avg()函数、统计记录的行数count()函数、最大值max()函数和最小值min()函数等。

group by子句的语法格式group by 字段列表

select 字段列表 from 数据源 Where 条件表达式 group by 分组字段
首先使用where子句对结果集进行过滤筛选,接着group by子句分组where子句的输出,


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤影墨客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值