• DOS命令行操作MySQL常用命令


    平时用可视化界面用惯了,如果紧急排查问题,没有安装可视化工具的话,只能通过命令来看了。

    以备不时之需,我们要熟悉一下命令行操作MySQL。

    打开DOS命令窗口:WIN + R 输入cmd,回车

    然后输入命令:mysql -uroot -proot -h127.0.0.1  【-u 用户名 -p密码 -h host地址】

    这里连接的是本地MySQL服务(先确保服务已启动)

    输入 show databases; (有分号) 输出所有数据库

    输入use demo 切换到demo数据库

    输入show tables; 输出该数据库下所有表名

    查询表数据:select * from fruit_type

    出现中文乱码,原因是登陆时使用的是lastin码,所以需要重新退出使用编码明确登陆。

    输入 exit 或 Ctrl + C退出,重新登录输入命令:mysql -uroot -proot -h127.0.0.1 --default-character-set=GBK

    再来查询

     查看执行计划 explain select * from fruit_type where type_id = 1;

     

    查看表结构:desc tableName;

    查询表中列的注释信息

    select * from information_schema.columns
    where table_schema = 'demo' 
    and table_name = 'fruit_type' ;

    只查询列名和注释
    select column_name, column_comment from information_schema.columns where table_schema ='demo' and table_name = 'fruit_type' ;

    图片太长了

    查看表的注释
    select table_name,table_comment from information_schema.tables where table_schema = 'demo' and table_name ='fruit_type';

    我这个没写注释。

    表操作命令:
    复制表结构:create table table1 like table;
    复制数据:insert into table1 select * from table

    机器授权:
    grant select on *.* to 'reader'@'%' identified by '123456' WITH GRANT OPTION
    flush privileges

    修改表结构
    alter table fruit_type add addr VARCHAR2(20) unsigned DEFAULT NULL COMMENT '产地';

  • 相关阅读:
    OpenSSL生成rsa密钥对
    RabbitMQ工作模式
    加密解密
    MongDB优化
    java线程进程
    MongoDB数据类型
    获取指针指向的内存大小方法
    [教程] 让Mac OS 10.x.x安装在Vmware虚拟机上!
    安装好的苹果系统部分截图
    VC中MFC程序手动控制最近文件列表
  • 原文地址:https://www.cnblogs.com/ibigboy/p/11281209.html
Copyright © 2020-2023  润新知