安装完MySQL之后,使用了自定义的配置文件来启动MySQL,发现配置在[mysql]中的prompt并没有生效

[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql3376.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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>

  配置文件my3376.cnf的配置如下

[mysql]
no-auto-rehash
max_allowed_packet = 128M
prompt = '(product)\u@\h [\d]> '
default_character_set = utf8

  使用print-defaults查看:

[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql --print-defaults
/usr/local/mysql/bin/mysql would have been started with the following arguments:

  得到的结果没有输出prompt的信息

  官方文档的描述如下:

  You can set the prompt in several ways:

  • First,Use an environment variable. You can set the MYSQL_PS1 environment variable to a prompt string. For example:

  • shell> export MYSQL_PS1="(\u@\h) [\d]> "
  • Second,Use a command-line option. You can set the --prompt option on the command line to mysql. For example:

    shell> mysql --prompt="(\u@\h) [\d]> "
    (user@host) [database]>
  • Third,Use an option file. You can set the prompt option in the [mysql] group of any MySQL option file, such as /etc/my.cnf or the .my.cnf file in your home directory. For example:

    [mysql]
    prompt=(\\u@\\h) [\\d]>\\_

    In this example, note that the backslashes are doubled. If you set the prompt using the prompt option in an option file, it is advisable to double the backslashes when using the special prompt options. There is some overlap in the set of permissible prompt options and the set of special escape sequences that are recognized in option files. (The rules for escape sequences in option files are listed in Section 4.2.6, “Using Option Files”.) The overlap may cause you problems if you use single backslashes. For example, \s is interpreted as a space rather than as the current seconds value. The following example shows how to define a prompt within an option file to include the current time in HH:MM:SS> format:

    [mysql]
    prompt="\\r:\\m:\\s> "
  • Fourth,Set the prompt interactively. You can change your prompt interactively by using the prompt (or \R) command. For example:

    mysql> prompt (\u@\h) [\d]>\_
    PROMPT set to '(\u@\h) [\d]>\_'
    (user@host) [database]>
    (user@host) [database]> prompt
    Returning to default PROMPT of mysql>
    mysql>

  根据官方文档提示的第三点,尝试着把prompt添加到/etc/my.cnf下

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

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links= [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [mysql]
prompt=\\u@\\h:\\p [\\d]>

  测试登录,能得到预想的提示结果

[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql3376.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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:mysql3376.sock [(none)]>

  使用print-defaults查看输出信息

[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql --print-defaults
/usr/local/mysql/bin/mysql would have been started with the following arguments:
--prompt=\u@\h:\p [\d]>

  考虑到官方文档中提示会读取到/etc/my.cnf和~/.my.cnf下的prompt,就容易联想到是不是mysql客户端就只能读取到默认路径下的[mysql]?

  继续做以下尝试:

[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql --verbose --help | grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

  注:按照顺序,每次做下一次测试之前都把前一个my.cnf中的[mysql]中的prompt注释掉

  • /etc/mysql/my.cnf
[root@MySQL56_L1 mysql]# vi /etc/mysql/my.cnf 

[mysql]
prompt=\\u@\\h:\\p [\\d]>
-----------------------------------------------------------------------------------
# 测试登录
[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql3376.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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:mysql3376.sock [(none)]>
  • /usr/local/mysql/etc/my.cnf
[root@MySQL56_L1 mysql]# vi /usr/local/mysql/etc/my.cnf

[mysql]
prompt=\\u@\\h:\\p [\\d]>
------------------------------------------------------------------------------------
# 测试结果
[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql3376.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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:mysql3376.sock [(none)]>
  • ~/.my.cnf
[root@MySQL56_L1 mysql]# vi ~/.my.cnf

[mysql]
prompt=\\u@\\h:\\p [\\d]>
------------------------------------------------------------------------------------
[root@MySQL56_L1 ~]# /usr/local/mysql/bin/mysql -S /tmp/mysql3376.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log MySQL Community Server (GPL) Copyright (c) , , 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:mysql3376.sock [(none)]>

  结论: 要使prompt生效,必须是把prompt添加到mysql能读取到的默认的配置文件下的[mysql]下。

  以上,如有错谬,请不吝指正。

 

MySQL的prompt不生效的问题的更多相关文章

  1. prompt不生效之解决

    配置文件路径: /data/mysql/mysql3306/my.cnf [client]port = 3306 [mysql]auto-rehashprompt="\\u@\\h:\\p ...

  2. Mysql 权限修改何时生效

    首先权限是记录在表中的,所以如果我们要修改权限只要修改表中的数据就可以了! 方法 1 grant ,revoke,set password,rename user .......等等 2 insert ...

  3. linux下面MySQL变量修改及生效

    今天在访问mysql项目的时候突然报500错误,没有找到连接,因此想到mysql的连接时间. mysql> show global variables; 主要就是连接时间是28800(8小时), ...

  4. prompt更改MySQL登陆后的提示符

    临时生效 mysql> prompt \u@standby \r:\m:\s > PROMPT set to '\u@standby \r:\m:\s >' root@standby ...

  5. 解决mysql配置文件my.cnf添加max_connections不生效

    问题描述: 最新为了方便测试,通过mysql官方指定的yum源安装了mysql5.6.40,在向mysql的配置文件my.cnf添加max_connections=3600后,重启mysql后发现不生 ...

  6. Mysql安装脚本

    Mysql PS:要先看懂脚本在复制粘贴运行脚本,每个人的环境不一样 #/bin/bash #--------变量 #num=` + ` now_lujing=`pwd` #------------- ...

  7. 涂抹mysql笔记-mysql复制特性

    <>mysql复制特性:既可以实现整个服务(all databases)级别的复制,也可以只复制某个数据库或某个数据库中的某个指定的表对象.即可以实现A复制到B(主从单向复制),B再复制到 ...

  8. mysql系列之3.mysql进阶

    启动原理 mysqld脚本-->mysqld_safe脚本-->mysqld服务-->启动mysql 强制关闭mysql: 三种方法, 不建议用! killall mysqld pk ...

  9. mysql 多实例案例实战

    其实Mysql多实例就是在一个 mysql 服务上面启动三个实例,相当于三个分离开来的数据库,至于为什么要做这个,你也可以选择分别安装三个MySQL,只是过于麻烦,多实例中只需要一个配置档my.cnf ...

随机推荐

  1. linux 环境下tomcat中部署jfinal项目

    tomcat中部署jfinal项目 问题现象如下图 问题描述: 我在自己的windows7系统上tomcat下面跑这个项目没有任何问题吗,但是当我把项目上传到linux服务器上的tomcatwebap ...

  2. import与from...import...的区别

    from ... import ... 的用法和直接import的区别: 1.直接使用import时,如果需要使用到导入模块内的属性和方法,必须使用模块名.属性和模块名.方法的方式进行调用 2.使用f ...

  3. P3970 [TJOI2014]上升子序列

    传送门 DP 十分显然的DP,但是不好写 设 f[ i ] 表示以第 i 个数作结尾时的方案数,原序列为 a 如果不考虑相同的序列: 那么转移就是 Σ f[ j ] (0< j < i & ...

  4. 关于form组件的补充-------formChoice

    form组件的Choice字段 还是基于出版社和书的模型来详解 models.py(模型) from django.db import models # Create your models here ...

  5. python3+selenium获取列表某一列的值

    python3+selenium获取列表某一列的值 我们在坐自动化测试时,我们可能不想单纯的想验证一个选项卡,我们让脚本随机选择一个选项进行接下来的操作.例如我们想获取列表某一列的某一个数据(随机的) ...

  6. cpp中memset函数的注意点

    可参考: C++中memset函数的用法 C++中memset函数的用法 C++中memset()函数的用法详解 c/c++学习系列之memset()函数 透彻分析C/C++中memset函数 mem ...

  7. 3DMAx Panda Directx Exporter 导出 X插件

    Panda Directx Exporter 下载地址 http://www.andytather.co.uk/Panda/directxmax_downloads.aspx 将下载的文件解压后,放到 ...

  8. shell 终端字符颜色

    终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关,shell,python,perl等均可以调用. 转义序列是以 ESC 开头,可以用 \033 完成相同的工作(ESC ...

  9. Selenium+Python+Webdriver:保存截图到指定文件夹

    保存图片到指定文件夹: from selenium import webdriverfrom pathlib import Pathfrom time import sleepdriver = web ...

  10. 05-spring整合jdbc-jdbc模板对象JdbcTemplate

    1 演示JdbcTemplate模板对象 1 导包 2 准备数据库 3 书写UserDao package www.test.dao; import java.util.List; import ww ...