数据库mysql基础2

数据库基础2

引擎

mysql 从 5.5.5 开始 默认引擎 是 innodb

以前是 MyISAM

查看 引擎

show engines \G # mysql 以 分号为结尾 \G分行显示 最佳阅读体验

myisam、innodb 区别
  1. myisam不支持事务 表锁 支持全文索引 不支持外键 读取效率高 如果你这张表读的多那么选择 myisam 引擎 更好
  2. myisam只缓存索引文件 数据文件的缓存 由 操作系统来完成
  3. innodb 支持事务、行锁 、支持外键

指定表引擎

创建表的时候 mysql> create table test6(id int(11))engine=myisam;
alter table 表名 engine=innodb;

增删改查

插入记录

  1. insert into 表名 values(值1,值2,值3,…值n);

    INSERT into users VALUE('13999999999',8,'ruirui','yangyang','123456',19); #value只能插入一行
    
    mysql> insert into users values('13888888888',1,'lijiarui','binggege','123abc',18);
    Query OK, 1 row affected (0.01 sec)  #插入一条记录  values 支持插入多行记录
    
    mysql> insert into users values('13888888888',2,'lijiarui','binggege','123abc',18),('13888888888',5,'lijiarui','binggege','123abc',18),('13888888888',3,'lijiarui','binggege','123abc',18),('13888888888',4,'lijiarui','binggege','123abc',18);  #插入多条
    Query OK, 4 rows affected (0.01 sec)
    Records: 4  Duplicates: 0  Warnings: 0
    
  2. insert into 表名(字段1,字段2,…,字段n) values(值1,值2,值3,…值n);

    mysql> insert into users(id,user_name,password) value(13,'haha','heiheihei');
    mysql> insert into users(id,user_name,password) values(9,'张三','123abc'),(10,'lisi','6666777'),(11,'wangwu','123123'),(12,'zhao
    si','9999120');
    
  3. 修改表字段 为主键自增 不用每次插入数据再插入主键了

    mysql> alter table test1 modify id int(11) not null primary key auto_increment;
    

查询

select

诸如 python中的print

mysql> select '66666' as haha;  # as 这里是起个别名

mysql> select '66666';
+-------+
| 66666 |
+-------+
| 66666 |
+-------+
1 row in set (0.00 sec)
mysql> select '66666' as haha;
+-------+
| haha  |
+-------+
| 66666 |
+-------+
1 row in set (0.00 sec)
查询语句 语法

select * from 表名

select 字段1,字段2,…字段n from 表名;

select 字段1[as 别名],字段2,…字段n from 表名;

mysql> select * from users;  
mysql> select id,user_name,age from users;
mysql> select id,user_name as 姓名,age as 年龄 from users;
单个字段不重复 distinct
mysql> select distinct user_name as 用户名 from users;
+----------+
| 用户名   |
+----------+
| binggege |
| yangyang |
| 张三     |
| lisi     |
| wangwu   |
| zhaosi   |
| haha     |
+----------+
7 rows in set (0.00 sec)
where 条件
符号 说明
> 大于
< 小于
= 等于
>= 大于等于
<= 小于等于
!= 不等于
and 并且
or 或者
is
is not 不是
select * from users where id<=5;
select * from users where id<=8 and age>18; #同时满足 and 左右的条件才出来结果  
select * from users where id<=8 or age>18; # 满足其中一个就返回
mysql> select * from users where jiaruilee is not null; #判断 jiaruilee  不为空的 
mysql> select * from users where jiaruilee is null; # jiaruilee 为空的 
like
mysql> select * from stars where username like '范冰冰&#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值