MySQL常用黑窗口命令

文章目录

    • 启动、停止mysql
    • mysql登录命令
    • 查看数据库版本
    • 显示所有数据库
    • 进入指定的数据库
    • 显示当前数据库中所有的表
    • 查看其他数据库中所有的表
    • 查看表的创建语句
    • 查看表结构
    • 查看当前所在库
    • 查看当前mysql支持的存储引擎
    • 查看系统变量及其值
    • 查看某个系统变量
    • 查询一个表中的索引

启动、停止mysql

停止命令:net stop mysql
启动命令:net start mysql

C:\Windows\system32>net stop mysql
mysql 服务正在停止.
mysql 服务已成功停止。
C:\Windows\system32>net start mysql
mysql 服务正在启动 .
mysql 服务已经启动成功。

mysql登录命令

mysql -h ip -P 端口 -u 用户名 -p

C:\Windows\system32>mysql -h localhost -P 3306 -u root -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

查看数据库版本

mysql --version 或者mysql -V( 用于在未登录情况下,查看本机mysql版本)

C:\Windows\system32>mysql -V
mysql Ver 14.14 Distrib 5.7.25, for Win64 (x86_64)
C:\Windows\system32>mysql --version
mysql Ver 14.14 Distrib 5.7.25, for Win64 (x86_64)

select version(); (登录情况下,查看数据库版本)

mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.27-log |
+------------+
1 row in set (0.01 sec)

显示所有数据库

show databases;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| boot_crm           |
| employee           |
| javacode2018       |
| mybatis            |
| mysql              |
| performance_schema |
| spring             |
| ssmcrud            |
| student            |
+--------------------+
10 rows in set (0.01 sec)

进入指定的数据库

use 数据库名;

mysql> use mybatis;
Database changed

显示当前数据库中所有的表

show tables;

mysql> show tables;
+-------------------+
| Tables_in_mybatis |
+-------------------+
| acount            |
| t_customer        |
| t_student         |
| t_user            |
| tb_idcard         |
| tb_orders         |
| tb_ordersitem     |
| tb_person         |
| tb_product        |
| tb_user           |
+-------------------+
10 rows in set (0.00 sec)

查看其他数据库中所有的表

show tables from 数据库名;

mysql> show tables from student;
+-------------------+
| Tables_in_student |
+-------------------+
| que               |
| stu               |
| tea               |
+-------------------+
3 rows in set (0.00 sec)

查看表的创建语句

show create table 表名;

mysql> show create table acount;
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                                                                                                      |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| acount | CREATE TABLE `acount` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(10) NOT NULL,
  `balance` double(10,0) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

查看表结构

desc 表名;

mysql> desc acount;
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(10)      | NO   | PRI | NULL    | auto_increment |
| user_name | varchar(10)  | NO   |     | NULL    |                |
| balance   | double(10,0) | NO   |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

查看当前所在库

select database();

mysql> select database();
+------------+
| database() |
+------------+
| mybatis    |
+------------+
1 row in set (0.00 sec)

查看当前mysql支持的存储引擎

SHOW ENGINES;

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

查看系统变量及其值

SHOW VARIABLES;

mysql> SHOW VARIABLES;
+----------------------------------------------------------+--------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------+
| Variable_name                      | Value       
                                       
                                       
                                       
                                       
                              |
+----------------------------------------------------------+--------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------+
| auto_increment_increment                 | 1         
                                       
                                       
                                       
                                       
                              |
| auto_increment_offset                  | 1         
                                       
                                       
                                       
                                       
                              |
| autocommit                        | ON        
                                       
                                       
                                       
                                       
                               |
| automatic_sp_privileges                 | ON        
                                       
                                       
                                       
                                       
                               |
| avoid_temporal_upgrade                  | OFF        
                                       
                                       
                                       
                                       
                              |
| back_log                         | 90        
                                       
                                       
                                       
                                       
                               |
| basedir                         |
D:\installsoft\MySQL\mysql-5.7.25-winx64\                   
......
.....
....
+----------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
513 rows in set, 1 warning (0.00 sec)

查看某个系统变量

SHOW VARIABLES like ‘变量名’;

mysql> SHOW VARIABLES like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 28800 |
+---------------+-------+
1 row in set, 1 warning (0.00 sec)

mysql> SHOW VARIABLES like '%wait_timeou%t';
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| innodb_lock_wait_timeout | 50       |
| lock_wait_timeout        | 31536000 |
| wait_timeout             | 28800    |
+--------------------------+----------+
3 rows in set, 1 warning (0.00 sec)

查询一个表中的索引

SHOW INDEXS FROM ‘表名’;

mysql> show index from tb_idcard;
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table     | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| tb_idcard |          0 | PRIMARY  |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.01 sec)

mysql> show index from tb_ordersitem;
+---------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table         | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| tb_ordersitem |          0 | PRIMARY    |            1 | id          | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
| tb_ordersitem |          1 | orders_id  |            1 | orders_id   | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| tb_ordersitem |          1 | product_id |            1 | product_id  | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+---------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

你可能感兴趣的:(数据库)