MySQL:查看当前的状态
MySQL的默认提示符是“mysql>”,不论你是否进入了其他的数据库,永远都是一样的提示符。
因此,有时候你需要确定,当前会话的状态信息:
我是谁?
我进入到了什么数据库?
当前的字符集又是什么情况?
等等。
要获得以上方面的信息,大概可以通过下列方式初步得到:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
[root@rhel71 ~]# mysqlplus.sh Login MySQL Service @ rhel71:3306 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.7-rc-log Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> status -------------- /usr/local/mysql/bin/mysql Ver 14.14 Distrib 5.7.7-rc, for Linux (x86_64) using EditLine wrapper Connection id: 3 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.7-rc-log Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysql/mysql.sock Uptime: 1 hour 7 min 17 sec Threads: 2 Questions: 76 Slow queries: 0 Opens: 22 Flush tables: 1 Open tables: 15 Queries per second avg: 0.018 -------------- mysql> mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) mysql> select database(); +------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec) mysql> mysql> show tables; ERROR 1046 (3D000): No database selected mysql> mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | adamhuandb | | alienware | | miyue | | mysql | | performance_schema | | sys | +--------------------+ 7 rows in set (0.00 sec) mysql> mysql> use adamhuandb; 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> mysql> status -------------- /usr/local/mysql/bin/mysql Ver 14.14 Distrib 5.7.7-rc, for Linux (x86_64) using EditLine wrapper Connection id: 3 Current database: adamhuandb Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.7-rc-log Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysql/mysql.sock Uptime: 1 hour 9 min 11 sec Threads: 2 Questions: 88 Slow queries: 0 Opens: 22 Flush tables: 1 Open tables: 15 Queries per second avg: 0.021 -------------- mysql> mysql> select database(); +------------+ | database() | +------------+ | adamhuandb | +------------+ 1 row in set (0.00 sec) mysql> mysql> |
————————————————
Done。