有没有办法将 DB 用户密码传递到命令行工具 mysqladmin 中?

我目前使用以下方法,但它总是提示我手动键入密码。在启动可执行文件时,是否有办法将它传递到命令行?

mysqladmin processlist -u root -p
90167 次浏览

Try:

--password=PasswordTextHere

Just found out the answer....

mysqladmin processlist -u root -pYOURPASSWORDHERE

No space between your password and the -p

This should work: mysql -uroot -p'password'

If you're trying to automate mysql solution, you can use password from variable:

mysql_pass=$(sudo grep -oP "temporary password is generated for root@localhost: \K(.*)" /var/log/mysqld.log)

mysql -uroot -p"$mysql_pass" < somescript.sql