MySQL数据库基本操作

进入数据库;

开始菜单进入MySQL Command Line Client

输入密码

1.查看数据库: show databases;(注意不区分大小写,语句结尾要加上;)

2.进入数据库:use 数据库名称;

3.查看数据库中表的结构:desc 表名称;

4.查看数据库里表的具体内容:select * from 表名;

5.新建表: create table 表名   (
                                                             id int,
                                                             name char(15),
                                                             age int
                                                      );   // 最基本格式

通用格式:create table [if not exists]  表名称(

字段名1 列类型 [属性] [索引],

字段名2 列类型 [属性] [索引],

字段名3 列类型 [属性] [索引],

字段名n 列类型 [属性] [索引]

)[表类型][表字符集]; //其中属性 包括1.unsigned 2.zerofill 3.auto_incremnet(自动增长)4.null 和not null 5.default

                                            索引 包括1.主键索引primary key(每个表只能有一个) 2.唯一索引unique(防止创建重复的值,可以有多个唯一索引)3.常规索引 (提神数据库的性能)

6.向表中插入数据:   insert into 表名 (id,name,age) values(0259,"wuhan",28);


7.修改表: 添加 alter table 表名 add sex char(2) not null;

                   删除 alter table hehe drop sex;

                   修改字段名: alter table hehe change name username char(10);

                   修改列类型:alter table hehe modify username char(15);


8 增删查改:更新: update hehe set age="23" where id>100&&id<2000;

                     删除:delete from hehe where id>500;

                     查询语句:select * from hehe where id>500&&id<10000;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值