启动及关闭 MySQL 服务器
Windows 系统下
启动 MySQL 服务器:
1、通过 "服务" 管理工具: 打开"运行"对话框(Win + R),输入 services.msc,找到"MySQL"服务,右击选择"启动"。
**2、通过命令提示符:**打开命令提示符(以管理员身份),输入以下命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">net start mysql</span></span></span>
关闭MySQL服务器:
1、**通过 "服务" 管理工具:**同样打开"运行"对话框,输入 services.msc,找到 "MySQL" 服务,右击选择"停止"。
2、通过命令提示符: 打开命令提示符(以管理员身份),输入以下命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">net stop mysql</span></span></span>
Linux 系统下
1、启动 MySQL 服务:
使用 systemd 命令(适用于大多数现代 Linux 发行版,如 Ubuntu、CentOS 等):
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo systemctl start mysql</span></span></span>
使用 service 命令(在一些较旧的发行版中):
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo service mysql start</span></span></span>
2、关闭 MySQL 服务:
使用 systemd:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo systemctl stop mysql</span></span></span>
使用 service 命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo service mysql stop</span></span></span>
3、重启 MySQL 服务:
使用 systemd:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo systemctl restart mysql</span></span></span>
使用 service 命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo service mysql restart</span></span></span>
4、检查 MySQL 服务状态:
使用 systemd命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo systemctl status mysql</span></span></span>
使用 service 命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo service mysql status</span></span></span>
Mac OS 系统
启动 MySQL 服务:
使用命令行:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo </span><span style="color:#171c19">/</span><span style="color:#171c19">usr</span><span style="color:#171c19">/</span><span style="color:#55859b">local</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">/</span><span style="color:#171c19">support</span><span style="color:#171c19">-</span><span style="color:#171c19">files</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">.</span><span style="color:#171c19">server start</span></span></span>
关闭 MySQL 服务:
使用命令行:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo </span><span style="color:#171c19">/</span><span style="color:#171c19">usr</span><span style="color:#171c19">/</span><span style="color:#55859b">local</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">/</span><span style="color:#171c19">support</span><span style="color:#171c19">-</span><span style="color:#171c19">files</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">.</span><span style="color:#171c19">server stop</span></span></span>
重启 MySQL 服务:
使用命令行:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo </span><span style="color:#171c19">/</span><span style="color:#171c19">usr</span><span style="color:#171c19">/</span><span style="color:#55859b">local</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">/</span><span style="color:#171c19">support</span><span style="color:#171c19">-</span><span style="color:#171c19">files</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">.</span><span style="color:#171c19">server restart</span></span></span>
检查 MySQL 服务状态:
使用命令行:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">sudo </span><span style="color:#171c19">/</span><span style="color:#171c19">usr</span><span style="color:#171c19">/</span><span style="color:#55859b">local</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">/</span><span style="color:#171c19">support</span><span style="color:#171c19">-</span><span style="color:#171c19">files</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">.</span><span style="color:#171c19">server status</span></span></span>
以上命令中,mysql 可能会因为安装路径或版本的不同而有所变化。
在 Mac OS 中,MySQL 的安装路径通常是 /usr/local/mysql/,因此启动和关闭 MySQL 服务需要使用这个路径下的 mysql.server 脚本。
MySQL 用户设置
在 MySQL 中,用户设置包括创建用户、设置权限、管理用户等操作。以下是一些常用的 MySQL 用户设置操作,包括创建用户、设置权限、查看和删除用户等。
创建用户
要创建一个新用户,你可以使用以下 SQL 命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">CREATE USER </span><span style="color:#489963">'username'</span><span style="color:#171c19">@</span><span style="color:#489963">'host'</span><span style="color:#171c19"> IDENTIFIED BY </span><span style="color:#489963">'password'</span><span style="color:#171c19">;</span></span></span>
username
:用户名。host
:指定用户可以从哪些主机连接。例如, 仅允许本地连接, 允许从任何主机连接。localhost``%
password
:用户的密码。
实例
创建****由"password123"标识****的用户"john"@"localhost";
授权权限
创建用户后,你需要授予他们访问权限,使用 GRANT 命令来授予权限:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">GRANT privileges ON database_name</span><span style="color:#171c19">.*</span><span style="color:#171c19"> TO </span><span style="color:#489963">'username'</span><span style="color:#171c19">@</span><span style="color:#489963">'host'</span><span style="color:#171c19">;</span></span></span>
privileges
:所需的权限,如 、、、、 等。ALL PRIVILEGES``SELECT``INSERT``UPDATE``DELETE
database_name.*
:表示对某个数据库或表授予权限。 表示对整个数据库的所有表授予权限, 表示对指定的表授予权限。database_name.*``database_name.table_name
TO 'username'@'host'
:指定授予权限的用户和主机。
实例
GRANT ALL PRIVILEGES ON test_db.* TO 'john'@'localhost';
刷新权限
授予或撤销权限后,需要刷新权限使更改生效:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">FLUSH PRIVILEGES</span><span style="color:#171c19">;</span></span></span>
查看用户权限
要查看特定用户的权限,可以使用以下命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">SHOW GRANTS FOR </span><span style="color:#489963">'username'</span><span style="color:#171c19">@</span><span style="color:#489963">'host'</span><span style="color:#171c19">;</span></span></span>
实例
SHOW GRANTS FOR 'john'@'localhost';
撤销权限
要撤销用户的权限,使用 REVOKE 命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">REVOKE privileges ON database_name</span><span style="color:#171c19">.*</span><span style="color:#171c19"> FROM </span><span style="color:#489963">'username'</span><span style="color:#171c19">@</span><span style="color:#489963">'host'</span><span style="color:#171c19">;</span></span></span>
实例
REVOKE ALL PRIVILEGES ON test_db.* FROM 'john'@'localhost';
删除用户
如果需要删除用户,可以使用以下命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">DROP USER </span><span style="color:#489963">'username'</span><span style="color:#171c19">@</span><span style="color:#489963">'host'</span><span style="color:#171c19">;</span></span></span>
实例
DROP USER 'john'@'localhost';
修改用户密码
要修改用户的密码,可以使用 ALTER USER 命令:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">ALTER USER </span><span style="color:#489963">'username'</span><span style="color:#171c19">@</span><span style="color:#489963">'host'</span><span style="color:#171c19"> IDENTIFIED BY </span><span style="color:#489963">'new_password'</span><span style="color:#171c19">;</span></span></span>
实例
ALTER USER 'john'@'localhost' IDENTIFIED BY 'newpassword456';
修改用户主机
要更改用户的主机(即允许从哪些主机连接),可以先删除用户,再重新创建一个新的用户。
实例
-- 删除旧用户
DROP USER 'john'@'localhost';
-- 重新创建用户并指定新的主机
CREATE USER 'john'@'%' IDENTIFIED BY 'password123';
创建用户时指定权限
在创建用户时,也可以同时授予权限(在 MySQL 8.0.16 及更高版本):
实例
CREATE USER 'john'@'localhost' IDENTIFIED BY 'password123' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON test_db.* TO 'john'@'localhost';
/etc/my.cnf 文件配置
/etc/my.cnf 文件是 MySQL 配置文件,用于配置 MySQL 服务器的各种参数和选项。
一般情况下,你不需要修改该配置文件,该文件默认配置如下:
prettyprint
<span style="background-color:#ecf4ee"><span style="color:#333333"><span style="color:#171c19">[</span><span style="color:#171c19">mysqld</span><span style="color:#171c19">]</span><span style="color:#171c19">
datadir</span><span style="color:#171c19">=</span><span style="color:#489963">/var/</span><span style="color:#171c19">lib</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql
socket</span><span style="color:#171c19">=</span><span style="color:#489963">/var/</span><span style="color:#171c19">lib</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">/</span><span style="color:#171c19">mysql</span><span style="color:#171c19">.</span><span style="color:#171c19">sock
</span><span style="color:#171c19">[</span><span style="color:#171c19">mysql</span><span style="color:#171c19">.</span><span style="color:#171c19">server</span><span style="color:#171c19">]</span><span style="color:#171c19">
user</span><span style="color:#171c19">=</span><span style="color:#171c19">mysql
basedir</span><span style="color:#171c19">=</span><span style="color:#489963">/var/</span><span style="color:#171c19">lib
</span><span style="color:#171c19">[</span><span style="color:#171c19">safe_mysqld</span><span style="color:#171c19">]</span><span style="color:#171c19">
err</span><span style="color:#171c19">-</span><span style="color:#171c19">log</span><span style="color:#171c19">=</span><span style="color:#489963">/var/</span><span style="color:#171c19">log</span><span style="color:#171c19">/</span><span style="color:#171c19">mysqld</span><span style="color:#171c19">.</span><span style="color:#171c19">log
pid</span><span style="color:#171c19">-</span><span style="color:#171c19">file</span><span style="color:#171c19">=</span><span style="color:#489963">/var/</span><span style="color:#171c19">run</span><span style="color:#171c19">/</span><span style="color:#171c19">mysqld</span><span style="color:#171c19">/</span><span style="color:#171c19">mysqld</span><span style="color:#171c19">.</span><span style="color:#171c19">pid</span></span></span>
在配置文件中,你可以指定不同的错误日志文件存放的目录,一般你不需要改动这些配置。
/etc/my.cnf 文件在不同的系统和 MySQL 版本中可能有所不同,但是一般包含以下几个部分:
1. 基本设置
basedir
: MySQL 服务器的基本安装目录。datadir
: 存储 MySQL 数据文件的位置。socket
: MySQL 服务器的 Unix 套接字文件路径。pid-file
: 存储当前运行的 MySQL 服务器进程 ID 的文件路径。port
: MySQL 服务器监听的端口号,默认是 3306。
2. 服务器选项
bind-address
: 指定 MySQL 服务器监听的 IP 地址,可以是 IP 地址或主机名。server-id
: 在复制配置中,为每个 MySQL 服务器设置一个唯一的标识符。default-storage-engine
: 默认的存储引擎,例如 InnoDB 或 MyISAM。max_connections
: 服务器可以同时维持的最大连接数。thread_cache_size
: 线程缓存的大小,用于提高新连接的启动速度。query_cache_size
: 查询缓存的大小,用于提高相同查询的效率。default-character-set
: 默认的字符集。collation-server
: 服务器的默认排序规则。
3. 性能调优
innodb_buffer_pool_size
: InnoDB 存储引擎的缓冲池大小,这是 InnoDB 性能调优中最重要的参数之一。key_buffer_size
: MyISAM 存储引擎的键缓冲区大小。table_open_cache
: 可以同时打开的表的缓存数量。thread_concurrency
: 允许同时运行的线程数。
4. 安全设置
skip-networking
: 禁止 MySQL 服务器监听网络连接,仅允许本地连接。skip-grant-tables
: 以无需密码的方式启动 MySQL 服务器,通常用于恢复忘记的 root 密码,但这是一个安全风险。auth_native_password=1
: 启用 MySQL 5.7 及以上版本的原生密码认证。
5. 日志设置
log_error
: 错误日志文件的路径。general_log
: 记录所有客户端连接和查询的日志。slow_query_log
: 记录执行时间超过特定阈值的慢查询。log_queries_not_using_indexes
: 记录未使用索引的查询。
6. 复制设置
master_host
和 : 主服务器的地址和复制用户。master_user
master_password
: 复制用户的密码。master_log_file
和 : 用于复制的日志文件和位置。master_log_pos
管理MySQL的命令
以下列出了使用Mysql数据库过程中常用的命令:
-
USE 数据库名 :
选择要操作的Mysql数据库,使用该命令后所有Mysql命令都只针对该数据库。
prettyprint<span style="background-color:#ecf4ee"><span style="color:#171c19">mysql</span><span style="color:#171c19">></span> <span style="color:#55859b">use</span><span style="color:#171c19"> RUNOOB</span><span style="color:#171c19">;</span> <span style="color:#478c90">Database</span><span style="color:#171c19"> changed</span></span>
-
SHOW DATABASES:
列出 MySQL 数据库管理系统的数据库列表。
prettyprint<span style="background-color:#ecf4ee"><span style="color:#171c19">mysql</span><span style="color:#171c19">></span><span style="color:#171c19"> SHOW DATABASES</span><span style="color:#171c19">;</span> <span style="color:#171c19">+--------------------+</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Database</span> <span style="color:#171c19">|</span> <span style="color:#171c19">+--------------------+</span> <span style="color:#171c19">|</span><span style="color:#171c19"> information_schema </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> RUNOOB </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> cdcol </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> mysql </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> onethink </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> performance_schema </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> phpmyadmin </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> test </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> wecenter </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> wordpress </span><span style="color:#171c19">|</span> <span style="color:#171c19">+--------------------+</span> <span style="color:#9f713c">10</span><span style="color:#171c19"> rows </span><span style="color:#55859b">in</span> <span style="color:#55859b">set</span> <span style="color:#171c19">(</span><span style="color:#9f713c">0.02</span><span style="color:#171c19"> sec</span><span style="color:#171c19">)</span></span>
-
SHOW TABLES:
显示指定数据库的所有表,使用该命令前需要使用 use 命令来选择要操作的数据库。
prettyprint<span style="background-color:#ecf4ee"><span style="color:#171c19">mysql</span><span style="color:#171c19">></span> <span style="color:#55859b">use</span><span style="color:#171c19"> RUNOOB</span><span style="color:#171c19">;</span> <span style="color:#478c90">Database</span><span style="color:#171c19"> changed mysql</span><span style="color:#171c19">></span><span style="color:#171c19"> SHOW TABLES</span><span style="color:#171c19">;</span> <span style="color:#171c19">+------------------+</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Tables_in_runoob</span> <span style="color:#171c19">|</span> <span style="color:#171c19">+------------------+</span> <span style="color:#171c19">|</span><span style="color:#171c19"> employee_tbl </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> runoob_tbl </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> tcount_tbl </span><span style="color:#171c19">|</span> <span style="color:#171c19">+------------------+</span> <span style="color:#9f713c">3</span><span style="color:#171c19"> rows </span><span style="color:#55859b">in</span> <span style="color:#55859b">set</span> <span style="color:#171c19">(</span><span style="color:#9f713c">0.00</span><span style="color:#171c19"> sec</span><span style="color:#171c19">)</span></span>
-
SHOW COLUMNS FROM 数据表:
显示数据表的属性,属性类型,主键信息 ,是否为 NULL,默认值等其他信息。
prettyprint<span style="background-color:#ecf4ee"><span style="color:#171c19">mysql</span><span style="color:#171c19">></span><span style="color:#171c19"> SHOW COLUMNS FROM runoob_tbl</span><span style="color:#171c19">;</span> <span style="color:#171c19">+-----------------+--------------+------+-----+---------+-------+</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Field</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Type</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Null</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Key</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Default</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Extra</span> <span style="color:#171c19">|</span> <span style="color:#171c19">+-----------------+--------------+------+-----+---------+-------+</span> <span style="color:#171c19">|</span><span style="color:#171c19"> runoob_id </span><span style="color:#171c19">|</span> <span style="color:#55859b">int</span><span style="color:#171c19">(</span><span style="color:#9f713c">11</span><span style="color:#171c19">)</span> <span style="color:#171c19">|</span><span style="color:#171c19"> NO </span><span style="color:#171c19">|</span><span style="color:#171c19"> PRI </span><span style="color:#171c19">|</span><span style="color:#171c19"> NULL </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> runoob_title </span><span style="color:#171c19">|</span><span style="color:#171c19"> varchar</span><span style="color:#171c19">(</span><span style="color:#9f713c">255</span><span style="color:#171c19">)</span> <span style="color:#171c19">|</span><span style="color:#171c19"> YES </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> NULL </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> runoob_author </span><span style="color:#171c19">|</span><span style="color:#171c19"> varchar</span><span style="color:#171c19">(</span><span style="color:#9f713c">255</span><span style="color:#171c19">)</span> <span style="color:#171c19">|</span><span style="color:#171c19"> YES </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> NULL </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> submission_date </span><span style="color:#171c19">|</span><span style="color:#171c19"> date </span><span style="color:#171c19">|</span><span style="color:#171c19"> YES </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> NULL </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span> <span style="color:#171c19">+-----------------+--------------+------+-----+---------+-------+</span> <span style="color:#9f713c">4</span><span style="color:#171c19"> rows </span><span style="color:#55859b">in</span> <span style="color:#55859b">set</span> <span style="color:#171c19">(</span><span style="color:#9f713c">0.01</span><span style="color:#171c19"> sec</span><span style="color:#171c19">)</span></span>
-
SHOW INDEX FROM 数据表:
显示数据表的详细索引信息,包括PRIMARY KEY(主键)。
prettyprint<span style="background-color:#ecf4ee"><span style="color:#171c19">mysql</span><span style="color:#171c19">></span><span style="color:#171c19"> SHOW INDEX FROM runoob_tbl</span><span style="color:#171c19">;</span> <span style="color:#171c19">+------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Table</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Non_unique</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Key_name</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Seq_in_index</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Column_name</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Collation</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Cardinality</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Sub_part</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Packed</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Null</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Index_type</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Comment</span> <span style="color:#171c19">|</span> <span style="color:#478c90">Index_comment</span> <span style="color:#171c19">|</span> <span style="color:#171c19">+------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+</span> <span style="color:#171c19">|</span><span style="color:#171c19"> runoob_tbl </span><span style="color:#171c19">|</span> <span style="color:#9f713c">0</span> <span style="color:#171c19">|</span><span style="color:#171c19"> PRIMARY </span><span style="color:#171c19">|</span> <span style="color:#9f713c">1</span> <span style="color:#171c19">|</span><span style="color:#171c19"> runoob_id </span><span style="color:#171c19">|</span><span style="color:#171c19"> A </span><span style="color:#171c19">|</span> <span style="color:#9f713c">2</span> <span style="color:#171c19">|</span><span style="color:#171c19"> NULL </span><span style="color:#171c19">|</span><span style="color:#171c19"> NULL </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span><span style="color:#171c19"> BTREE </span><span style="color:#171c19">|</span> <span style="color:#171c19">|</span> <span style="color:#171c19">|</span> <span style="color:#171c19">+------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+</span> <span style="color:#9f713c">1</span><span style="color:#171c19"> row </span><span style="color:#55859b">in</span> <span style="color:#55859b">set</span> <span style="color:#171c19">(</span><span style="color:#9f713c">0.00</span><span style="color:#171c19"> sec</span><span style="color:#171c19">)</span></span>
-
SHOW TABLE STATUS [FROM db_name] [LIKE 'PATTERN'] \G:
该命令将输出Mysql数据库管理系统的性能及统计信息。
prettyprint<span style="background-color:#ecf4ee"><span style="color:#171c19">mysql</span><span style="color:#171c19">></span><span style="color:#171c19"> SHOW TABLE STATUS FROM RUNOOB</span><span style="color:#171c19">;</span> <span style="color:#78877d"># 显示数据库 RUNOOB 中所有表的信息</span><span style="color:#171c19"> mysql</span><span style="color:#171c19">></span><span style="color:#171c19"> SHOW TABLE STATUS </span><span style="color:#55859b">from</span><span style="color:#171c19"> RUNOOB LIKE </span><span style="color:#489963">'runoob%'</span><span style="color:#171c19">;</span> <span style="color:#78877d"># 表名以runoob开头的表的信息</span><span style="color:#171c19"> mysql</span><span style="color:#171c19">></span><span style="color:#171c19"> SHOW TABLE STATUS </span><span style="color:#55859b">from</span><span style="color:#171c19"> RUNOOB LIKE </span><span style="color:#489963">'runoob%'</span><span style="color:#171c19">\G</span><span style="color:#171c19">;</span> <span style="color:#78877d"># 加上 \G,查询结果按列打印</span></span>
Gif 图演示: