1. //1.查询库
    2. mysql> show databases;
    3. +--------------------+
    4. | Database |
    5. +--------------------+
    6. | information_schema |
    7. | mysql |
    8. | performance_schema |
    9. | test |
    10. | ytl |
    11. +--------------------+
    12. 5 rows in set (0.00 sec)
    13. //2.切换选择库
    14. mysql> use mysql;
    15. Reading table information for completion of table and column names
    16. You can turn off this feature to get a quicker startup with -A
    17. Database changed
    18. mysql>
    19. //查看库里的表
    20. mysql> show tables;
    21. +---------------------------+
    22. | Tables_in_mysql |
    23. +---------------------------+
    24. | columns_priv |
    25. | db |
    26. | event |
    27. | func |
    28. | general_log |
    29. | help_category |
    30. | help_keyword |
    31. | help_relation |
    32. | help_topic |
    33. | innodb_index_stats |
    34. | innodb_table_stats |
    35. | ndb_binlog_index |
    36. | plugin |
    37. | proc |
    38. | procs_priv |
    39. | proxies_priv |
    40. | servers |
    41. | slave_master_info |
    42. | slave_relay_log_info |
    43. | slave_worker_info |
    44. | slow_log |
    45. | tables_priv |
    46. | time_zone |
    47. | time_zone_leap_second |
    48. | time_zone_name |
    49. | time_zone_transition |
    50. | time_zone_transition_type |
    51. | user |
    52. +---------------------------+
    53. 28 rows in set (0.00 sec)
    54. //查看表里的字段
    55. mysql> desc user;
    56. +------------------------+-----------------------------------+------+-----+-----------------------+-------+
    57. | Field | Type | Null | Key | Default | Extra |
    58. +------------------------+-----------------------------------+------+-----+-----------------------+-------+
    59. | Host | char(60) | NO | PRI | | |
    60. | User | char(16) | NO | PRI | | |
    61. | Password | char(41) | NO | | | |
    62. | Select_priv | enum('N','Y') | NO | | N | |
    63. | Insert_priv | enum('N','Y') | NO | | N | |
    64. | Update_priv | enum('N','Y') | NO | | N | |
    65. | Delete_priv | enum('N','Y') | NO | | N | |
    66. | Create_priv | enum('N','Y') | NO | | N | |
    67. | Drop_priv | enum('N','Y') | NO | | N | |
    68. | Reload_priv | enum('N','Y') | NO | | N | |
    69. | Shutdown_priv | enum('N','Y') | NO | | N | |
    70. | Process_priv | enum('N','Y') | NO | | N | |
    71. | File_priv | enum('N','Y') | NO | | N | |
    72. | Grant_priv | enum('N','Y') | NO | | N | |
    73. | References_priv | enum('N','Y') | NO | | N | |
    74. | Index_priv | enum('N','Y') | NO | | N
    75. //查看建表语句
    76. mysql> show create table user\G;
    77. *************************** 1. row ***************************
    78. Table: user
    79. Create Table: CREATE TABLE `user` (
    80. `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
    81. `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
    82. `Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
    83. `Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
    84. `Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
    85. `Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
    86. `Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
    87. `Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
    88. `Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
    89. `Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
    90. 6. 查看当前用户
    91. mysql> select user();
    92. +----------------+
    93. | user() |
    94. +----------------+
    95. | root@localhost |
    96. +----------------+
    97. 1 row in set (0.00 sec)
    98. 7.查看当前使用的数据库
    99. mysql> select database();
    100. +------------+
    101. | database() |
    102. +------------+
    103. | mysql |
    104. +------------+
    105. 1 row in set (0.00 sec)
    106. 8.创建库
    107. mysql> create database db1;
    108. Query OK, 1 row affected (0.00 sec)
    109. 9. 创建表
    110. mysql> create table t1(
    111. -> id int(4),
    112. -> name char(40)
    113. -> );
    114. Query OK, 0 rows affected (0.01 sec)
    115. 10.查看当前数据库版本
    116. mysql> select version();
    117. +-----------+
    118. | version() |
    119. +-----------+
    120. | 5.6.47 |
    121. +-----------+
    122. 1 row in set (0.00 sec)
    123. 11.查看数据库状态
    124. mysql> show status;
    125. +-----------------------------------------------+-------------+
    126. | Variable_name | Value |
    127. +-----------------------------------------------+-------------+
    128. | Aborted_clients | 0 |
    129. | Aborted_connects | 8 |
    130. | Binlog_cache_disk_use | 0 |
    131. | Binlog_cache_use | 0 |
    132. | Binlog_stmt_cache_disk_use | 0 |
    133. | Binlog_stmt_cache_use | 0 |
    134. | Bytes_received | 1071 |
    135. | Bytes_sent | 27483 |
    136. | Com_admin_commands | 0 |
    137. | Com_assign_to_keycache | 0 |
    138. | Com_alter_db | 0 |
    139. | Com_alter_db_upgrade | 0 |
    140. 12.查看各参数
    141. mysql> show variables;show variables like'max_connect%';
    142. 456 rows in set (0.00 sec)
    143. +--------------------+-------+
    144. | Variable_name | Value |
    145. +--------------------+-------+
    146. | max_connect_errors | 100 |
    147. | max_connections | 151 |
    148. +--------------------+-------+
    149. 2 rows in set (0.00 sec)
    150. 13.修改参数
    151. mysql> set global max_connect_errors=1000;
    152. Query OK, 0 rows affected (0.00 sec)
    153. 14. 查看队列
    154. mysql> show processlist;show full processlist;
    155. +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
    156. | Id | User | Host | db | Command | Time | State | Info |
    157. +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
    158. | 1 | system user | | NULL | Connect | 7370 | Connecting to master | NULL |
    159. | 2 | system user | | NULL | Connect | 7370 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL |
    160. | 17 | root | localhost | NULL | Query | 0 | init | show processlist |
    161. +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
    162. 3 rows in set (0.00 sec)
    163. +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+-----------------------+
    164. | Id | User | Host | db | Command | Time | State | Info |
    165. +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+-----------------------+
    166. | 1 | system user | | NULL | Connect | 7370 | Connecting to master | NULL |
    167. | 2 | system user | | NULL | Connect | 7370 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL |
    168. | 17 | root | localhost | NULL | Query | 0 | init | show full processlist |
    169. +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+-----------------------+
    170. 3 rows in set (0.00 sec)