zoukankan      html  css  js  c++  java
  • Mysql指令

    打开方式:下载phpstudy,通过phpstudy打开数据库。

          phpstudy->其他选项菜单->Mysql工具->Mysql命令行。

    打开后输入密码 root 。

    指令:

    1.show databases;(语句结束后必须写分号)查看数据库的指令。

    +-----------------------------+

    |  Database                   |

    +-----------------------------+

    | information_schema   |

    | mysql                          |

    | performance_schema|

    | test                             |

    +----------------------------+

    2.create database 数据库名;         创建数据库

    我创建了一个叫d1的数据库后,用show databases;输出后显示为:

    +-----------------------------+

    |  Database                   |

    +-----------------------------+

    | information_schema   |

    | d1                               |

    | mysql                          |

    | performance_schema|

    | test                             |

    +----------------------------+

    3.drop database 数据库名;      删除数据库

    删除的d1数据库后,就显示为原来的。

    4.use 数据库名;       进入某一个数据库

    输入指令后会显示    Database changed     ,代表进入数据库成功。

    5.create table; 表名(字段1 类型,字段2 类型);

    6.show tables;   查看数据表       

    +-----------------------------+

    |  Tables_in_d2             |

    +-----------------------------+

    | information_schema   |

    | t1                                |

    +-----------------------------+

    7.drop table 表名;     删除表

    8.alter table 表名 rename 新表名;      修改表名

    9.alert table 表名 add 定义字段;   添加字段

    10.alert table 表名 drop 字段名;    删除字段

    11.alert table 表名 change 旧的字段名 字段定义;   修改字段

    12.alert table 表名 modify 字段定义;   修改字段类型

    对字段进行操作

    13.desc 表名; 查看表的定义

    +-------------+---------------+------------+----------+--------------+----------------+

    |Field         | Type           | Null        | Key      | default      | Extra           |

    +-------------+---------------+------------+----------+--------------+----------------+

    | id             |  init(11)  | YES       |             |  NULL       |                     |

    | name       |  init(11)  | YES       |             |  NULL       |                     |

    +-------------+---------------+------------+----------+--------------+----------------+

    14.inset into 表名(id,age) value(值1,值2);    给字段添加数据(记录)一条

     inset into 表名 values(),(),();    多条

    15.查看记录

    select * from 表名;查看所有的字段

    select id from 表名;查看单个的字段

    select id,age from 表名;查看多个字段记录

    16.按条件查询

    select * from 表名 where 条件;          条件表达式 > < >= <= = !=   and且   or或

    select * from t3 where age>30 and age<50;

    17.排序查询

    select * from 表名 order by 字段名 [asc/desc];

    asc 由低到高      desc 由高到低

    select * from t3 order by age desc;

    18.限制查询

    select * from 表名 limit 2,5;     从第2个开始向后查询5个

    select * from 表名 limit 5;   查询5个

    19.删除记录

    删除所有  delete from 表名;

    按条件删  delete from 表名 where 条件表达式;

    delete from t3 where id=3; 

    20.改数据 

    update 表名 set 字段=值;

    如果不带条件,会把字段下面的记录全改。

    21.按条件更新

    update t3 set age=56 where id=6;

  • 相关阅读:
    HDU4812 D Tree(树的点分治)
    BZOJ1834 [ZJOI2010]network 网络扩容(最小费用最大流)
    HDU4862 Jump(放大边权的费用流)
    SCU3185 Black and white(二分图最大点权独立集)
    HDU3729 I'm Telling the Truth(字典序最大的最大流)
    HDU3586 Information Disturbing(树形DP)
    HDU3657 Game(最小割)
    POJ3162 Walking Race(树形DP+尺取法+单调队列)
    SCU3312 Stockholm Knights(最大流)
    Codeforces 161D Distance in Tree(树的点分治)
  • 原文地址:https://www.cnblogs.com/yangzhiqiang/p/10686088.html
Copyright © 2011-2022 走看看