MySQL数据库基本操作

来源:互联网 发布:进口食品js号 编辑:程序博客网 时间:2024/04/30 09:00

进入数据库;

开始菜单进入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
原创粉丝点击