zoukankan      html  css  js  c++  java
  • MySQL中一些基础查询操作(适用于MariaDB)

    1、登录操作,没有密码或者有密码,则需要输入密码

    mysql -uroot
    或者
    mysql -uroot -p

    2、登录后,查询当前用户所拥有的数据库

    show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | test42           |
    | expressdelivery    |
    | information_schema |
    | insight            |
    | mysql              |
    | performance_schema |
    | test5               |
    | test               |
    +--------------------+
    

      

    3、切换数据库

    use insight;

    看到如下输出,则说明切换正确

    Database changed
    [insight]> 
    

      

    4、查询当前库下的表

    show tables;
    
    +---------------------+
    | Tables_in_insight   |
    +---------------------+
    | address_count_daily |
    | biz_temp_exception  |
    | matched_matter      |
    | matter_access       |
    | matter_count_daily  |
    | matter_match        |
    | matter_question     |
    | matter_tj           |
    | matter_xd           |
    | matter_xd_A         |
    | matter_xd_a         |
    | matter_xd_test      |
    | metric_config       |
    | taiji_count_daily   |
    | testmatter          |
    +---------------------+
    

      

    5、展示某一张表的所有列名称

    desc biz_temp_exception; 
    或者
    show columns from biz_temp_exception;
    +----------------+---------------+------+-----+---------+----------------+
    | Field          | Type          | Null | Key | Default | Extra          |
    +----------------+---------------+------+-----+---------+----------------+
    | id             | bigint(11)    | NO   | PRI | NULL    | auto_increment |
    | sn             | varchar(32)   | NO   | MUL | NULL    |                |
    | operator       | varchar(32)   | NO   | MUL | NULL    |                |
    | operator_phone | varchar(32)   | NO   |     | NULL    |                |
    | operator_desc  | varchar(1000) | NO   |     | NULL    |                |
    | operator_time  | datetime      | YES  | MUL | NULL    |                |
    | created_by     | varchar(32)   | YES  |     | NULL    |                |
    | created_time   | datetime      | YES  |     | NULL    |                |
    | updated_by     | varchar(32)   | YES  |     | NULL    |                |
    | updated_time   | datetime      | YES  |     | NULL    |                |
    +----------------+---------------+------+-----+---------+----------------+
    

      

    6、其他不同形式展示表结构的语句

    show create table table_name;  //查表字段信息和字符集信息
    select * from table_name;  //查表所有内容
    select * from table_name where id=?;  //查指定行
    select field_name from table_name; //查指定列,field意为字段
    select * from table_name where field_name like "%???%";  //根据字段内容的近似值查找指定行
    select field_name1,field_name2 from table_name; //查指定字段的多个列
    update table_name set field_name="abc" where id=?;  // 修改指定字段的内容
    

      

    7、普通展示数据和后缀加上 G展示数据,加上G展示形式更容易查看

    select * from biz_temp_exception G;
    
    *************************** 1. row ***************************
             id: 11
    matter_code: 2222
      matter_vs: 1
      dept_code: 11111
      dept_name: 2222
      need_form: 0
     need_stuff: 1
    create_time: 1536546243
    update_time: 1536546243
         config: NULL
    *************************** 2. row ***************************
             id: 22
    matter_code: 333
      matter_vs: 1
      dept_code: 111
      dept_name: 3333
      need_form: 0
     need_stuff: 1
    create_time: 1536546520
    update_time: 1536546520
         config: NULL
    

      

    8、查看当前数据库的版本信息,登录进来之后,输入命令status

    --------------
    mysql  Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1
    
    Connection id:          1805
    Current database:       
    Current user:           xxx
    SSL:                    Not in use
    Current pager:          stdout
    Using outfile:          ''
    Using delimiter:        ;
    Server:                 MariaDB
    Server version:         10.3.11-MariaDB MariaDB Server
    Protocol version:       10
    Connection:             Localhost via UNIX socket
    Server characterset:    latin1
    Db     characterset:    latin1
    Client characterset:    utf8
    Conn.  characterset:    utf8
    UNIX socket:            /xxx/mysql.sock
    Uptime:                 87 days 18 hours 48 min 6 sec
    
    Threads: 8  Questions: 73846  Slow queries: 0  Opens: 115  Flush tables: 1  Open tables: 106  Queries per second avg: 0.009
    --------------

    9、mysql查看、修改数据库、表字符集的方法

     请咨询度娘和谷歌。

  • 相关阅读:
    潜水员
    混合背包
    多重背包问题
    归并排序——最省时的排序
    HDU 1556 Color the ball
    2016 ACM/ICPC Asia Regional Dalian Online Football Games
    poj 2352 Stars
    poj 2299 Ultra-QuickSort
    关于原码反码补码以及位元算
    2016 湖南省省赛 Problem A: 2016
  • 原文地址:https://www.cnblogs.com/yuchuan/p/mysql_base.html
Copyright © 2011-2022 走看看