今天在操作数据库的时候,不知道进去了哪个库,那我们怎么查看当前你正在操作的数据库呢。我总结了一下总共有四种方式
进行查看,今天也写一写,强化一下基础。
1,使用命令:select database();
mysql> select database(); +------------+ | database() | +------------+ | NULL
| +------------+ 1 row in set (0.00 sec)/*从查询结果可以看出,我们当前没有进入到任何数据库。所以为NULL*/
mysql> use test; /*我们进入test库。*/ mysql> select database(); /*再次执行。*/
+------------+ | database() | +------------+ | test | +------------+ 1 row in
set (0.00 sec)/*从查询结果可以看出,我们当前没有进入到任何数据库。*/2,show tables;
+----------------+| Tables_in_test | +----------------+ | login | |
login_view | +----------------+ 2 rows in set (0.00 sec)
/*从第一行中可以看出我们目前正处在test库中*/
3,status;
mysql> status -------------- mysql Ver 14.14 Distrib 5.6.23, for
linux-glibc2.5 (x86_64) using EditLine wrapper Connection id: 22 Current
database: test Current user: root@localhost SSL: Not in use Current pager:
stdout
/* Current database:后面跟着的就是当前库test */
4,通过修改mysql提示符来永久显示当前所属库。
1,链接客户端时通过参数指定 #mysql -uroot -pmysql --prompt 提示符参数2,链接上客户端后,通过prompt命令修改
mysql> prompt 提示符参数;mysql 提示符参数: \D -->完整的日期 \d -->当前数据库 \h -->服务器名称 \u -->当前用户
[root@bogon ~]# mysql -uroot -pmysql --prompt "\u@\h \d>" 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 24 Server
version: 5.6.23-enterprise-commercial-advanced MySQL Enterprise Server -
Advanced Edition (Commercial) 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. root@localhost (none)>prompt mysql> PROMPT set to
'mysql>' mysql>use test; 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>prompt \u@\h \d> PROMPT set to "\u@\h \d>"
root@localhost test>
热门工具 换一换