mysql 分析各个使用技巧

来源:互联网 发布:网络教育金融牌照 编辑:程序博客网 时间:2024/06/05 07:48

一丶数据库

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

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