本帖最后由 以谁为师 于 2016-3-11 14:37 编辑
mysql查看数据库、表-01
[SQL] 纯文本查看 复制代码 show databases;
#看看数据库名
use mysql
#进入数据库
show tables;
#看看表名
desc user;
#看看表结构
mysql> desc 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 | |
mysql> select host, user, password from user;
#看看表字段
+------------------+------+----------+
| host | user | password |
+------------------+------+----------+
| localhost | root | |
| www.to-share.net | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| www.to-share.net | | |
+------------------+------+----------+
mysql> SELECT HOST,USER FROM mysql.user;
#查询mysql数据库user表 'host、user'字段
+------------------+------+
| host | user |
+------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| www.to-share.net | |
| www.to-share.net | root |
+------------------+------+
扩展查看-02
[AppleScript] 纯文本查看 复制代码 show processlist;
#查看进程
show grants FOR root;
#查询 root 用户创建语句
show create DATABASE discuz;
#查询 创建数据库语句
show create table mysql.user;
#查询 创建表语句
查看数据库容量-03
[AppleScript] 纯文本查看 复制代码 1、进入information_schema 数据库(存放了其他的数据库的信息)
use information_schema;
2、查询所有数据的大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
3、查看指定数据库的大小:
比如查看数据库home的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';
4、查看指定数据库的某个表的大小
比如查看数据库home中 members 表的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members'; |