• mysql常用操作


    create database new_dbname;--新建数据库
    drop database old_dbnane; --删除数据库
    show databases;--显示数据库
    use databasename;--使用数据库
    select database();--查看已选择的数据库

    show tables;--显示当前库的所有表
    create table tablename(fieldname1 fieldtype1,fieldname2 fieldtype2,..)[ENGINE=engine_name];--创建表
    drop table tablename; --删除表
    create table tablename select statement;--通过子查询创建表
    desc tablename;--查看表结构
    show create table tablename;--查看建表语句

    alter table tablename add new_fielname new_fieldtype;--新增列
    alter table tablename add new_fielname new_fieldtype after 列名1;--在列名1后新增列
    alter table tablename modify fieldname new_fieldtype;--修改列
    alter table tablename drop fieldname;--删除列
    alter table tablename_old rename tablename_new;--表重命名

    insert into tablename(fieldname1,fieldname2,fieldnamen) valuse(value1,value2,valuen);--增
    delete from tablename [where fieldname=value];--删
    update tablename set fieldname1=new_value where filename2=value;--改
    select * from tablename [where filename=value];--查

    truncate table tablename;--清空表中所有数据,DDL语句

    show engines;--查看mysql现在已提供的存储引擎:
    show variables like '%storage_engine%';--查看mysql当前默认的存储引擎
    show create table tablename;--查看某张表用的存储引擎(结果的"ENGINE="部分)
    alter table tablename ENGINE=InnoDB--修改引擎
    create table tablename(fieldname1 fieldtype1,fieldname2 fieldtype2,..) ENGINE=engine_name;--创建表时设置存储引擎
    ---------------------
    作者:上杉绘梨衣-
    来源:CSDN
    原文:https://blog.csdn.net/wjlwangluo/article/details/78165588
    版权声明:本文为博主原创文章,转载请附上博文链接!

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/royjj/article/details/49822373
    mysql> CREATE TABLE `employees1` (
        ->   `id` int(11) NOT NULL,
        ->   `fname` varchar(30) DEFAULT NULL,
        ->   `lname` varchar(30) DEFAULT NULL,
        ->   `hired` date NOT NULL DEFAULT '1970-01-01',
        ->   `separated` date NOT NULL DEFAULT '9999-12-31',
        ->   `job_code` int(11) NOT NULL,
        ->   `store_id` int(11) DEFAULT NULL
        -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1
        -> /*!50100 PARTITION BY RANGE (store_id)
        -> (PARTITION p0 VALUES LESS THAN (6) ENGINE = InnoDB,
        ->  PARTITION p1 VALUES LESS THAN (11) ENGINE = InnoDB,
        ->  PARTITION p2 VALUES LESS THAN (16) ENGINE = InnoDB,
        ->  PARTITION p3 VALUES LESS THAN (21) ENGINE = InnoDB) */;
    Query OK, 0 rows affected (0.59 sec)


    mysql> show create table employees1;
    +------------
    | Table      | Create Table                                                                                           
    ------------------------------------------------------------------------------------------------------------------+
    | employees1 | CREATE TABLE `employees1` (
      `id` int(11) NOT NULL,
      `fname` varchar(30) DEFAULT NULL,
      `lname` varchar(30) DEFAULT NULL,
      `hired` date NOT NULL DEFAULT '1970-01-01',
      `separated` date NOT NULL DEFAULT '9999-12-31',
      `job_code` int(11) NOT NULL,
      `store_id` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1
    /*!50100 PARTITION BY RANGE (store_id)
    (PARTITION p0 VALUES LESS THAN (6) ENGINE = InnoDB,
     PARTITION p1 VALUES LESS THAN (11) ENGINE = InnoDB,
     PARTITION p2 VALUES LESS THAN (16) ENGINE = InnoDB,
     PARTITION p3 VALUES LESS THAN (21) ENGINE = InnoDB) */ |
    +------------
    1 row in set (0.11 sec)


    mysql> alter table employees1 drop partition p0,p3;     
    Query OK, 0 rows affected (0.14 sec)
    Records: 0  Duplicates: 0  Warnings: 0


    mysql>  show create table employees1;
    +--------------------------------------------------------------------------------------------+
    | Table      | Create Table                                                                                                  
    ------------------------------------------------------------------------------------------+
    | employees1 | CREATE TABLE `employees1` (
      `id` int(11) NOT NULL,
      `fname` varchar(30) DEFAULT NULL,
      `lname` varchar(30) DEFAULT NULL,
      `hired` date NOT NULL DEFAULT '1970-01-01',
      `separated` date NOT NULL DEFAULT '9999-12-31',
      `job_code` int(11) NOT NULL,
      `store_id` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1
    /*!50100 PARTITION BY RANGE (store_id)
    (PARTITION p1 VALUES LESS THAN (11) ENGINE = InnoDB,
     PARTITION p2 VALUES LESS THAN (16) ENGINE = InnoDB) */ |
    +-----------------------------------+

    1 row in set (0.02 sec)
    ---------------------
    作者:lixora
    来源:CSDN
    原文:https://blog.csdn.net/lixora/article/details/49822373
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    SQL Server 和Oracle 12C体系结构图
    SQL Server Latch
    MSSQL SSIS agent job运行出错
    sys.processes spid 和 blocked是同一个 session id
    黑苹果导致Windows时间不对或关机不断电
    MSSQL shrink数据库
    MSSQL 死锁或阻塞检测
    MSSQL不能shrink日志
    tomcat配置https协议
    ELK windows下部署测试
  • 原文地址:https://www.cnblogs.com/shenggong/p/10697073.html
Copyright © 2020-2023  润新知