数据库mysql基本操作

备注: # 当行注释 /**/ 多行注释

新建库 设置字符集

create database mydb CHARACTER set utf8;

查询库表

show databases;

切换库表

use mydb;

新建数据表 指定对应的类型 如

create table my_test(
id int(10),
name varchar(30)
);

查询表结构

desc my_test;

插入数据

insert into my_test values(1,‘张三’),(2,‘张三1’);

查询 表中数据

select * from my_test;

修改表中数据 id乘以2

update my_test set id=id*2;

删除表数据

delete from my_test where id=2;
(1)实践

建立有限制的数据

drop table user;
#创建用户列表
create table user(
id int unsigned primary key auto_increment comment ‘用户id’,
username varchar(20) unique not null comment ‘用户名’,
mobile char(11) not null comment ‘手机号码’,
gender enum(‘男’,‘女’,‘保密’) default ‘男’ not null comment ‘性别’,
reg_time timestamp default current_timestamp comment ‘注册时间’ default NOW(),
level tinyint unsigned not null comment ‘会员等级’ default 1
) default charset=utf8;
desc user;
#添加测试记录
insert into user values(null, ‘小明’, ‘12311111111’, ‘男’, ‘2018-01-01 11:11:11’,1);
insert into user values(null, ‘小李’, ‘12311111111’, ‘男’, current_timestamp, 2);
insert into user values(null, ‘小张’, ‘12311111111’, ‘男’, NOW(), 2);
insert into user(username, mobile) values(‘bb’, ‘12399900009’);

#查看用户表中的记录
select * from user;

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值