mysql常用查询
1、mysql> select user(); #查看当前用户;
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
1 row in set (0.01 sec)
mysql>
mysql> select database();
+------------+
| database() |
+------------+
| zhaoyun |
+------------+
1 row in set (0.00 sec)
+------------+
| database() |
+------------+
| zhaoyun |
+------------+
1 row in set (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-11-28 21:17:18 |
+---------------------+
+---------------------+
| now() |
+---------------------+
| 2011-11-28 21:17:18 |
+---------------------+
mysql> show full processlist ;
+----+------+-----------+-------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+-------+---------+------+-------+-----------------------+
| 5 | root | localhost | mysql | Query | 0 | NULL | show full processlist |
+----+------+-----------+-------+---------+------+-------+-----------------------+
1 row in set (0.00 sec)
+----+------+-----------+-------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+-------+---------+------+-------+-----------------------+
| 5 | root | localhost | mysql | Query | 0 | NULL | show full processlist |
+----+------+-----------+-------+---------+------+-------+-----------------------+
1 row in set (0.00 sec)
mysql> kill 5;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
5、mysql> show databases; #查看所有数据库
mysql> show databases ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| zhaoyun |
+--------------------+
4 rows in set (0.00 sec)
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| zhaoyun |
+--------------------+
4 rows in set (0.00 sec)
mysql>
mysql> use zhaoyun
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables ;
+-------------------+
| Tables_in_zhaoyun |
+-------------------+
| passwd |
| test |
+-------------------+
2 rows in set (0.01 sec)
mysql> show tables ;
+-------------------+
| Tables_in_zhaoyun |
+-------------------+
| passwd |
| test |
+-------------------+
2 rows in set (0.01 sec)
mysql> show grants ;
+---------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '565491d704013245' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
+---------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '565491d704013245' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
8、mysql>show grants for
zhaoyun@'localhost'; #查看其他用户的权限
mysql> show grants for
zhaoyun@'localhost';
+--------------------------------------------------------------------------------------+
| Grants for zhaoyun@localhost |
+--------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'zhaoyun'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `zhaoyun`.* TO 'zhaoyun'@'localhost' |
+--------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
+--------------------------------------------------------------------------------------+
| Grants for zhaoyun@localhost |
+--------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'zhaoyun'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `zhaoyun`.* TO 'zhaoyun'@'localhost' |
+--------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql>
mysql> +--------------------------------------------------------------------------------------+ | Grants for zhaoyun@localhost | +--------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'zhaoyun'@'localhost' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `zhaoyun`.* TO 'zhaoyun'@'localhost' | +--------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) \c
mysql>
mysql> +--------------------------------------------------------------------------------------+ | Grants for zhaoyun@localhost | +--------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'zhaoyun'@'localhost' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `zhaoyun`.* TO 'zhaoyun'@'localhost' | +--------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) \c
mysql>
本文转自zhaoyun00 51CTO博客,原文链接:
http://blog.51cto.com/zhaoyun/728269