• MySQL常用命令


    记录 MySQL 命令行常用命令行详解:

    1. 登录 MySQL。-u 和 -p 后面紧跟用户名和密码,没有空格。

    mysql -uroot -p'密码'

    2. 查看所有的数据库。

    show databases;

    3. 创建名为 test 的数据库

    create database test;

    4. 进入 test 数据库

    use test;

    5. 查看数据库里有多少张表

    show tables;

    6. 创建名为 t1 表,并创建两个字段,id、name,varchar 表示设置数据长度,用字符来字符来定义长度单位,其中 1 汉字 = 2 字符 = 2 字节

    create table t1(id varchar(20),name varchar(20));

    7. 向表中插入数据

    1. insert into t1 values("1","Tom");
    2. insert into t1 values("2","Jerry");

    8. 查看 t1 表数据内容

    select * from t1;

    9. id、name 多个条件查询

    select * from t1 where id = 1 and name = 'Tom';

    10. 查看 t1 表数据内容

    desc t1;

    11. 修改 name 字段的长度

    alter table t1 modify column name varchar(30);

    12. 修改 name 字段的内容

    update t1 set name =  'Tommy' where id = 1;

     13. 刷新权限

    flush privileges;

     14. 查看数据库字符集

    show variables like '%char%';

     15. 查看 MySQL 存储引擎

    show engines;

     16. 查看 MySQL 默认的存储引擎

    show variables like '%storage_engine%';

    17. 查看单个表的存储引擎

    show create table t1;

    show table status from test where name='t1' \G

     18. 修改 MySQL t1 表存储引擎

    alter table t1 engine=MyISAM;

     19.  查询整个MySQL实例里面存储引擎为MyISAM的表

          如果要查询某个库或所有实例里面表使用的存储引擎,那么可以使用information_schema.tables来查询。

    select table_catalog, table_schema, table_name, engine from information_schema.tables where engine='MyISAM';
    

     20.  查询 test 数据库里面存储引擎为 MyISAM 的表

    select table_catalog, table_schema, table_name, engine from information_schema.tables where table_schema='test' and engine='MyISAM';
    

     21. 清空表内容

    delete from t2;

     22. 删除表

    drop table t2;

    23.  删除 test_1 数据库

    drop database test_1;

    24. 退出 MySQL 

    exit

  • 相关阅读:
    计算机毕业设计Python+djang公务员考试信息管理系统(源码+系统+mysql数据库+Lw文档)
    Docker 单节点部署 Consul
    nSoftware.PowerShell.Server.2020
    报错 | RegExp2 is not defined
    WPF Image控件鼠标双击事件的实现
    SpringBoot-20-模块开发-404页面
    澳洲猫罐头如何?我亲自喂养过的优质猫罐头分享
    RabbitMQ 消息应答
    电子书制作软件Vellum mac中文版特点
    STM32CUBEMX开发GD32F303(7)----配置printf
  • 原文地址:https://blog.csdn.net/weixin_51004248/article/details/126487847