MySQL 查看当前数据库

今天在操作数据库的时候,不知道进去了哪个库,那我们怎么查看当前你正在操作的数据库呢。我总结了一下总共有四种方式进行查看,今天也写一写,强化一下基础。

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)

从查询结果可以看出,我们当前处于test数据库中。

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提示符来永久显示当前所属库

第一步 链接客户端时通过参数指定

#mysql -uroot -pmysql --prompt 提示符参数

第二步 链接上客户端后,通过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>
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值