1. MySQL basic view commands

  1. View all databases
mysql> show databases;
+---------------------------+
| Database                  |
+---------------------------+
| zyyy-enterprise-center    |
| zyyy-member-center        |
| zyyy-order-center         |
| zyyy-product-center       |
+---------------------------+
17 rows in set (0.26 sec)

Attachment: View all tables

mysql> show tables;
  1. View current database
mysql> select database();
+------------------------+
| database()             |
+------------------------+
| zyyy-enterprise-center |
+------------------------+
1 row in set (0.15 sec)
  1. Check the port used by the database
    (I have a question: there are usually many databases under one connection, but only one port is set: 3306, that is, the port of all databases is 3306? Can you set the data port separately?)
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.25 sec)
  1. Switching the database
    Pay attention to these two points, which are located at the upper left of the keyboard (below Esc), otherwise a syntax error may be reported. For example, the following database name with underlined, without these two points, will report an error.
mysql> use `zyyy-enterprise-center`;
Database changed
  1. View the database encoding
    Method 1:
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.20 sec)

character_set_client: the encoding method of the client;
character_set_connection: the encoding used to establish a connection;
character_set_database: the encoding of the database;
character_set_results: the encoding of the result set;
character_set_server: the encoding of the database server;
as long as the encoding methods used above are the same, then There will be no garbled problems.

Way two:

mysql> show variables like 'collation%';
+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database   | utf8mb4_general_ci |
| collation_server     | utf8mb4_unicode_ci |
+----------------------+--------------------+
3 rows in set (0.87 sec)
  1. View all user information in the database
mysql> select distinct concat('user: ''',user,'''@''',host,''';') as query from mysql.user;
+------------------------------------+
| query                              |
+------------------------------------+
| user: 'root'@'%';                  |
| user: 'root'@'218.70.169.6';       |
| user: 'mysql.session'@'localhost'; |
| user: 'mysql.sys'@'localhost';     |
| user: 'root'@'localhost';          |
+------------------------------------+
5 rows in set (0.17 sec)
  1. View the permissions of a user
mysql> show grants for 'root'@'localhost';
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.21 sec)
  1. View the maximum number of connections to the database
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 50000 |
+-----------------+-------+
1 row in set (0.24 sec)
  1. View the current number of connections to the database, the number of concurrent
mysql> show status like 'Threads%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 5     |
| Threads_connected | 76    |
| Threads_created   | 1704  |
| Threads_running   | 1     |
+-------------------+-------+
4 rows in set (0.18 sec)

Threads_cached: Represents how many idle threads are currently in the thread cache at this moment .
Threads_connected: Represents the number of currently established connections . Because a connection requires one thread, it can also be regarded as the number of threads currently being used.
Threads_created: Represents the number of threads created since the last service startup .
Threads_running: Represents the number of threads currently active (non-sleeping) . It does not mean the number of threads in use. Sometimes the connection is established, but the connection is in sleep state, and the corresponding thread here is also in sleep state.

  1. View data file storage path
mysql> show variables like '%datadir%';
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.18 sec)

Guess you like

Origin blog.csdn.net/weixin_43298913/article/details/106367711