zoukankan      html  css  js  c++  java
  • MySQL常用命令总结

      MySQL数据库对大小写不敏感,如id和ID,select和SELECT.。

    1.数据库

      create database <数据库名>  创建数据库

      use <数据库名>  连接数据库

      注:use表示当前连接上了哪个数据库,并不会影响对其他数据库的访问

              如: use db_1;

                      select * from db_2.logs

      drop database <数据库名> 删除数据库,不会提箱

      drop database if exists <数据库名> 如果存在,删除数据库

      show databases  查询所有数据库

      select version() 查询数据库版本

      select database() 查询数据库名称

    2.表

      show tables 查询所有表

      create table <表名>( <字段名1> <类型1>[,...<字段名n> <类型n>] )   创建数据库

      drop table  <表名>  删除表

      drop table if exist  <表名>  如果存在,删除表

      rename table <原表名> to <新表名>

      delete from <表名> where <表达式> 删除表中数据

      insert into <表名> [(<字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )] 插入数据

      update <表名> set 字段=值, ... where <表达式>  更新表中数据

      select <字段1,字段2, ...> from <表名> where <表达式> order by <字段x, ...> limit m,n group by <字段y, ...> having <表达式>  查询

      alert table <表名> add <字段名> <类型>[... 其他]  给表增加字段

      alert table <表名> drop <字段名>  删除表中的字段

      alert table <表名> change <原字段名>   <新字段名> <新的类型>  修改表中字段

      show index from <表名>  查询索引

      show keys from <表名>  查询索引

      alert table <表名> add index <索引名> (<字段名1[, 字段名2 ...]>) 给表添加索引

      alert table <表名> add unique <索引名> (<字段名>) 给表添加唯一索引

      alert table <表名> add primary key (<字段名>)   给表中的主键添加索引

    3.备份

      mysqldump -u <用户名> -p <数据库名>  >  导出的文件名        导出数据库,导出文件默认在mysql/bin目录下

      mysqldump -u <用户名> -p <数据库名>  <表名>   >  导出的文件名

  • 相关阅读:
    ovs QOS
    OpenvSwitch端口镜像
    MyCat入门指南
    Mycat跨分片Join
    MyCAT 命令行监控
    MyCat的分片规则
    FreeMarker初探--介绍
    FreeMarker初探--安装FreeMarker
    linux 安装配置zookeeper
    Maven 环境搭建及相应的配置
  • 原文地址:https://www.cnblogs.com/yolandaBlog/p/9098283.html
Copyright © 2011-2022 走看看