• 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 <数据库名>  <表名>   >  导出的文件名

  • 相关阅读:
    Linux下Redis集群环境的搭建
    redis: 6379端口下set值时出现 CLUSTERDOWN The cluster is down
    运行Maven工程总是报错:No goals have been specified for this build
    Centos6.5 配置Nginx开机自启动
    centos6.5无法访问网络
    centos6.5 nginx-1.8.0和ftp搭建图片服务器
    HTML中使图片居中显示
    使用InstallAnywhere工具打包Java_Web程序
    Android开发中Parcelable接口的使用方法
    Java8并行流使用注意事项
  • 原文地址:https://www.cnblogs.com/yolandaBlog/p/9098283.html
Copyright © 2020-2023  润新知