>  기사  >  데이터 베이스  >  Correctly setting your mysql prompt using sudo_MySQL

Correctly setting your mysql prompt using sudo_MySQL

WBOY
WBOY원래의
2016-06-01 13:13:241342검색

If you run multiple MySQL environments on multiple servers it’s a good habit to set your MySQL prompt to double check which server you are on.
however, using the MYSQL_PS1 environment variable I found this does not work under sudo (the normal way people run sudo).

I.e., the following syntax’s work.

$ mysql$ sudo su - -c mysql$ sudo su - ; mysql

but the following does not.

$ sudo mysql

The trick is actually to ensure via /etc/sudoers you inherit the MySQL_PS1 environment variable.

echo "export MYSQL_PS1=/"`hostname` [/d]> /"" | sudo tee /etc/profile.d/mysql.shecho 'Defaultsenv_keep += "MYSQL_PS1"' | sudo tee /tmp/mysqlsudo chmod 400 /tmp/mysqlsudo mv /tmp/mysql /etc/sudoers.d

Tags:mysql client,mysql prompt,MYSQL_PS1,sudo

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.