备战2022春招或暑期实习,本专栏会持续输出MySQL系列文章,祝大家每天进步亿点点!文末私信作者,我们一起去大厂。
本篇总结的是 《如何查看MySQL数据库状态及信息》,后续会每日更新~
关于《Redis入门到精通》、《并发编程》、《Java全面入门》、《鸿蒙开发》等知识点可以参考我的往期博客
相信自己,越活越坚强,活着就该逢山开路,遇水架桥!生活,你给我压力,我还你奇迹!目录
1、简介
2、正文
2.1 查看所有数据库
2.2 查看正在使用的数据库
2.3 查看当前数据库中的表
2.5 显示授权用户及其权限
2.6 查看服务器错误或警告信息
2.7 查看建库语句和建表语句
2.8 查看数据库端口
2.9 查看数据库索引大小
2.10 查看数据库大小
2.11 查看最大连接数
2.12 查看当前线程相关信息
2.13 查看文件存储路径
2.14 查看数据库编码
2.15 帮助指令
1、简介
现如今我们操作数据库,都是使用现成的数据库管理工具,比如Navicat、SQLyog等等。这些工具能够提供可视化操作界面,大大的提升了我们的操作效率,但是这样往往让我们忘却了很多数据库语句,比如建表语句、查询数据库信息等。这篇文章我们学习几个非常有用的语句,便于在没有可视化工具的时候给到你帮助。
2、正文
2.1 查看所有数据库
mysql> SHOW ERROES; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ERROES' at line 1 mysql> mysql> mysql> SHOW ERRORS; +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Level | Code | Message | +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ERROES' at line 1 | +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> SHOW WARNINGS; +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Level | Code | Message | +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WARRINGS' at line 1 | +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 s
mysql> SHOW CREATE TABLE user; +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | user | CREATE TABLE `user` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', `name` varchar(255) NOT NULL COMMENT '用户名', `age` int(11) NOT NULL COMMENT '年龄', `sex` smallint(6) NOT NULL COMMENT '性别', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec)
mysql> SELECT CONCAT(((ROUND(SUM(data_length), 4) + ROUND(SUM(index_length), 4)) / (1024 * 1024)), ' mb') AS 'Database Size' -> FROM tables -> WHERE table_schema = 'liziba'; +---------------+ | Database Size | +---------------+ | 0.01562500 mb | +---------------+ 1 row in set (0.00 sec)