Home > Database > Mysql Tutorial > body text

Correctly setting your mysql prompt using sudo_MySQL

WBOY
Release: 2016-06-01 13:13:24
Original
1341 people have browsed it

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
Copy after login

but the following does not.

$ sudo mysql
Copy after login

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
Copy after login

Tags:mysql client,mysql prompt,MYSQL_PS1,sudo

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!