mysql 分析各个使用技巧

一丶数据库

1.登陆mysql数据库

   mysql -uroot -p;

   输入密码后登陆进去。

2.修改mysql密码

   set password for root@localhost = password('新密码');

3.查看数据库:

  show databases;

4.新建数据库:

   create database dataBaseName;

5.删除数据库:

   drop database dataBaseName;

6.使用数据库:

  use dataBaseName;

二 丶表

1.查看某数据库中的表结构:

  show tables;

2.查看某表中的数据结构:

   desc tableName;

   describe tableName;

3.添加表:

 create table tableName(id Integer primary ket auto_increment, name varchar(20),age int,high int);

 create table if not exists tableName(字段参数);

4.删除表:

 drop table tableName;

 drop table if exists tableName;

5.修改表:

   1)修改表名:

        alter table oldTableName rename  [to] newTableName;

   2)增加表中的字段:

     alter table tableName add  (字段参数);//在表的最后一个位置增加字段

      alter table tableName add  (字段参数)[frist];//在表的第一个位置增加字段

      alter table tableName add  (字段参数)[after] 已存在的属性名;//在关键字所指属性名后边添加字段

      eg: alter table tableName add  name varchar(10) default 'chaochao' after id; 

   3)删除字段:

      alter table tableName drop 属性名;

       eg: alter table tableName drop id;

4)修改字段名称:

alter table tableName change oldFieldName newFieldName ;

eg: alter table tableName change oldFieldName newFieldName int default 1;

   5)修改字段的数据类型:

      alter table tableName modify 属性名 数据类型;

eg:alter table tableName modify name int;

6.修改字段的顺序:

alter table tableName modify 属性名1 数据类型 firs;// 属性1放到第一位

      alter table tableName modify 属性名1 数据类型 after 属性名2;//属性1放到2后面

7.查表:

基本语法:

Select <列的集合> from <表名> where <条件> group by <结果行>order by <排序字段和方式> limit count <限定行数>

1)查看表中某一字段中存储数据的值:

select name from tableName where name = ‘chaochao’;//查看某表中的某属性名的值

2 ) where 子句

3)group by 子句 分组子句

4)order by 排序字段和方式

desc 降序排列

asc 升序排列

5)limit count <限定行数输出>

limit 3

总之,查询语句是很重要的语句,使用非常灵活,但我们可以确认的是,查某表 查某列 ,至于显示结果的时候就是通过后面的参数设定来看自我选择了。




  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值