MySQL 有没有办法将数据库用户密码传递给命令行工具mysqladmin?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12665522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:03:07  来源:igfitidea点击:

Is there a way to pass the DB user password into the command line tool mysqladmin?

mysqlwindowswindows-server-2008mysqladmin

提问by Ethan Allen

I currently use the following but it ALWAYS prompts me to manually type the password. Is there any way to pass it in on the command line when launching the executable?

我目前使用以下,但它总是提示我手动输入密码。启动可执行文件时,有什么方法可以在命令行上传递它吗?

mysqladmin processlist -u root -p

回答by Ethan Allen

Just found out the answer....

刚刚找到答案....

mysqladmin processlist -u root -pYOURPASSWORDHERE

No space between your password and the -p

密码和 -p 之间没有空格

回答by ge0man

Try:

尝试:

--password=PasswordTextHere 

回答by 3lvinaz

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

这应该有效: mysql -uroot -p'password'

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

如果您尝试自动化 mysql 解决方案,您可以使用变量中的密码:

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

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

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

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