mysql 设置当前数据库_prompt如何设置实现登陆MySQL显示用户名及当前数据库

本文介绍如何通过修改MySQL配置文件/etc/my.cnf中的[prompt]选项,实现登陆MySQL后显示用户名、主机名及当前数据库,提高维护效率。步骤包括添加配置、重启服务,并展示了设置后的连接效果。
摘要由CSDN通过智能技术生成

prompt如何设置实现登陆MySQL显示用户名及当前数据库

发布时间:2020-05-28 16:55:08

来源:51CTO

阅读:211

作者:三月

栏目:数据库

下文给大家带来有关prompt如何设置实现登陆MySQL显示用户名及当前数据库内容,相信大家一定看过类似的文章。我们给大家带来的有何不同呢?一起来看看正文部分吧,相信看完prompt如何设置实现登陆MySQL显示用户名及当前数据库你一定会有所收获。

实验环境:[root@dbnode1 ~]# cat /etc/redhat-release

CentOS release 6.5 (Final)MySQL版本:

Server version: 5.6.33-log MySQL Community Server (GPL)

默认情况连接到 mysql 库后不会显示当前连接的数据库名。如下图,

101000.jpg

这样在登陆MySQL后每次都看不到当前用户和主机名以及当前的数据库信息,给维护工作带来不便。其实在登陆MySQL后可以通过设置MySQL配置文件的方式,显示以上信息。方法:修改MySQL配置文件/etc/my.cnf中的[mysqld]中的prompt选项。过程如下:

(1)打开MySQL的配置文件:编辑/etc/my.cnf 添加以下如下红颜色一行

[root@dbnode1 ~]# vi /etc/my.cnf

[client]

port = 3306

socket = /tmp/mysql.sock

prompt="\\u@\\h:\\d>"

#character_set_server = utf8

#character_set_client = utf8

[mysqld]备注:设置后重启MySQL 服务。 \u 表示用户名,  \h 表示主机名, \d 表示当前数据库。

设置格式可以添加相关符号比如[]等

(2)重启 MySQL 服务

[root@dbnode1 ~]# /etc/init.d/mysql restart

Shutting down MySQL...... SUCCESS!

Starting MySQL.................. SUCCESS!

(3)连接测试[root@dbnode1 ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.33-log MySQL Community Server(GPL)

Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarks of theirrespective

owners.

Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.

root@localhost:(none)>use mysql

Reading table information for completion of tableand column names

You can turn off this feature to get a quickerstartup with -A

Database changed

root@localhost:mysql>use test

Reading table information for completion of tableand column names

You can turn off this feature to get a quickerstartup with -A

Database changed

root@localhost:test>

说明:

关于配置文件/etc/my.cnf的修改中,prompt选项,可以通过帮助文档查看

--prompt 更多设置可以查看MySQL命令帮助

对于上文关于prompt如何设置实现登陆MySQL显示用户名及当前数据库,大家觉得是自己想要的吗?如果想要了解更多相关,可以继续关注我们的行业资讯板块。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值