在mysql中自动验证密码

nov*_*ovo 7 mysql linux postgresql

我是MySql的新手.在postgres中,我们可以使用.pgpass并保存用户密码,以便数据库可以在您访问或执行sql脚本时自动验证您的密码.我没有输入密码.

那么有没有办法在linux上为mysql做同样的事情?

谢谢

Bil*_*win 15

是的,您可以在主目录中将默认凭据和其他选项存储在名为$ HOME/.my.cnf的文件中

$ cat > $HOME/.my.cnf
[client]
user = scott
password = tiger
host = mydbserver
^D
Run Code Online (Sandbox Code Playgroud)

在MySQL 5.6中,您还可以在$ HOME/.mylogin.cnf中存储此文件的加密版本,请参阅http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html

$ mysql_config_editor set --user=scott --host=mydbserver --password
Enter password: ********
WARNING : 'client' path already exists and will be overwritten. 
 Continue? (Press y|Y for Yes, any other key for No) : y

$ mysql_config_editor print --all
[client]
user = scott
password = *****
host = mydbserver
Run Code Online (Sandbox Code Playgroud)