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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章