MySQL | MySQL 数据库系统(二)- SQL语句的基本操作
前言
通过本篇文章学习如何使用 MySQL 数据库系统的基本操作使用,也是我们在今后的工作中会有所运用的。
一、查看当前服务器中有哪些库
show databases 语句: 用于查看当前 MySQL 数据库系统中包含哪些库。
初始化后的 MySQL 数据库,默认有四个库分别是:
information_schema
mysql
performance_schema
test
(mysql库中包含了用户认证的相关表)
复制代码
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
复制代码
查看当前使用的库中有哪些表
show tables 语句: 用于查看当前所在的库中所包含的表。
操作前,需先使用 use 语句来切换到所要使用的库。
若你想要知道自己当前所使用的 mysql 库中包含哪些表,即可切换到 mysql 的目标库中,执行语句:show tables; 来进行查看 mysql 库中的表。
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| user |
+---------------------------+
24 rows in set (0.00 sec)
复制代码
查询表的结构
describe 语句: 用于显示表的结构,组成表的各字段信息。
需指定“库名,表名”来作为参数,指定表名时,需先使用 use 语句来切换到所要使用的库。
若查询表结构时,可通过如下语句来进行查看 mysql 库中的 user 表结构,同时也可以执行语句:describe mysql.user; 查看,所输出的结构是一致的。
mysql> describe user;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | YES | | | |
| authentication_string | text | YES | | NULL | |
+-