是开始希望不是结束,是起点希望不是终点html
今天在作MySQL练习过程当中,忽然发现,登录mysql后,命令行不能显示用户名和主机信息,同时呢,想查看数据库信息还须要查看select datebase()命令查看,特别不方便,所以特别查看了mysql的相关资料,每次经过客户端登录怎么才能显示这些信息呢?其实MySQL的相关设置都在配置文件my.cnf中能够设置。所以就去看my.cnf文件,以前就使用下,没有细心看。my.cnf配置文件中两大部分:[client]和[mysqld],前者是客户端的配置参数,后者是服务端的配置参数,既然问题是:客户端登录MySQL服务显示相关信息,那么配置应该在[client]当中,那么应该如何设置呢?请看下文一一解答。node
实验环境:mysql
[root@dbnode1 ~]# cat /etc/redhat-release CentOS release 6.5 (Final)
MySQL版本: Server version: 5.6.33-log MySQL Community Server (GPL)
默认状况链接到 mysql 库后不会显示当前链接的数据库名。以下图,sql
这样在登录MySQL后每次都看不到当前用户和主机名以及当前的数据库信息,给维护工做带来不便。其实在登录MySQL后能够经过设置MySQL配置文件的方式,显示以上信息。方法:修改MySQL配置文件/etc/my.cnf中的[mysqld]中的prompt选项。过程以下:数据库
(1)打开MySQL的配置文件:编辑/etc/my.cnf 添加如下以下红颜色一行bash
[root@dbnode1 ~]# vi /etc/my.cnfsocket
[client]ide
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选项,能够经过帮助文档查看
谢谢你们的阅读,技术学习之路还很长,愿与你一块儿成长!