2011-09-28 44 views

回答

0

你可以使用--defaults-file選項與外殼別名, 結合,例如:

% cat db01 
[mysql] 
user=root 
password=<your_pwd> 
host=<your_host> 


% alias my_db01='mysql --defaults-file=db01' 

% my_db01 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 41 
Server version: 5.1.54-1ubuntu4 (Ubuntu) 

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 
This software comes with ABSOLUTELY NO WARRANTY. This is free software, 
and you are welcome to modify and redistribute it under the GPL v2 license 

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

mysql> 

所以你可以創建具有不同設置不同的文件。

+0

我可以直接爲mysql -uuser -ppassword -hhost添加別名,而不是使用文件。但是,那不是我正在尋找的。謝謝你的回答 –

+0

是的,你可以。應該注意的是,在這種情況下,在某些操作系統中,您的密碼將在ps命令輸出中清晰可見。如果你想避免一個單獨的文件,並且你的shell支持進程替換,你可以使用像這樣的東西:'mysql --defaults-file = <(printf'[mysql] \ nuser =%s \ npassword =%s \ n'用戶傳遞)',所以在ps輸出是:'mysql> \! pgrep -lf mysql \ 6312 mysql --defaults-file =/dev/fd/63'。 –