[英]Passwordless mysql_connect
I have a cron job that calls a PHP script that causes the following error message. 我有一个cron作业,该作业调用了导致以下错误消息的PHP脚本。
Warning: Using a password on the command line interface can be insecure
I can currently connect to the database without a password prompt using mysql --login-path=foo
after using mysql_config_editor --login-path=foo --host=hostname --user=username --password
. 我现在可以在使用
mysql_config_editor --login-path=foo --host=hostname --user=username --password
之后使用mysql --login-path=foo
连接到数据库而没有密码提示。
However, I can't figure out how to set $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
但是,我不知道如何设置
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
to be passwordless. 无密码。
TIA TIA
I'm not sure if your MySQL account has a password or not, but I'm guessing password on the command line is probably stored in your my.cnf
file. 我不确定您的MySQL帐户是否有密码,但是我猜想命令行上的密码可能存储在
my.cnf
文件中。
In PHP, you don't have to supply the password parameter to `mysql_connect', and if you leave it empty it will look at an ini setting: http://php.net/manual/en/mysql.configuration.php#ini.mysql.default-password 在PHP中,您不必向“ mysql_connect”提供password参数,如果将其保留为空,它将查看ini设置: http : //php.net/manual/en/mysql.configuration.php# ini.mysql.default密码
I agree with @Patrick though, you should, where possible, not use mysql_* functions because they're deprecated, though I feel your pain as I currently work on a system that we can't yet upgrade. 我同意@Patrick的观点,但您应该尽可能不要使用mysql_ *函数,因为它们已被弃用,尽管我在当前无法升级的系统上工作时会感到不安。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.