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、mysql查看、修改数据库、表字符集的方法

 请参考:https://www.cnblogs.com/yangmingxianshen/p/7999428.html

 

MySQL中一些基础查询操作(适用于MariaDB)

上一篇:关于NodeJS中mysql连接池卡死问题


下一篇:go访问mysql基本语法