即使我的密码为空,mysql 也提示输入密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3843973/
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 17:20:02  来源:igfitidea点击:

mysql is prompting for password even though my password is empty

mysql

提问by Nick Vanderbilt

I installed mysql on ubuntu server and did not specify password. When I do

我在 ubuntu 服务器上安装了 mysql 并且没有指定密码。当我做

mysql -u root -p 

it prompts for password and without providing any input I just hit enter and it works.

它提示输入密码并且没有提供任何输入,我只是按回车键就可以了。

Now I need to perform some operation on the database using cron job. My cron job does not work because mysql prompts for a password. I tried doing

现在我需要使用 cron 作业对数据库执行一些操作。我的 cron 作业不起作用,因为 mysql 提示输入密码。我试着做

mysql -u root -p'' my_database

but that did not work either.

但这也不起作用。

Any suggestion?

有什么建议吗?

回答by sneilan

Go like this mysql -u root --password="" dbname

像这样去 mysql -u root --password="" dbname

回答by BillThor

Try not asking mysql to prompt for the password, 'mysql -u myuser'. I would suggest you create an account with only the required privileges to do this. Also limit its access to localhost. Put a password on root.

尽量不要让 mysql 提示输入密码,'mysql -u myuser'。我建议您创建一个仅具有执行此操作所需权限的帐户。还要限制其对 localhost 的访问。给root设置密码。

回答by Lightness Races in Orbit

I installed mysql on ubuntu server and did not specify password. When I do

mysql -u root -p

我在 ubuntu 服务器上安装了 mysql 并且没有指定密码。当我做

mysql -u root -p

-pbrings up the password prompt. If you do not have a password, then you do not want to do that.

-p调出密码提示。如果您没有密码,那么您就不想这样做。

Just write:

写就好了:

mysql -u root


For the love of god, get a password on that account!

看在上帝的份上,获取该帐户的密码!

回答by Yeti

Check MySQL Documentation for how to reset your password, since I found no way to enter a password either. You could use the following: http://dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.htmlWhich states that you have to create a file with the following query:

检查 MySQL 文档以了解如何重置密码,因为我也找不到输入密码的方法。您可以使用以下内容:http: //dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.html其中规定您必须使用以下查询创建文件:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

And then start up mysqld service with the --init-file parameter (see the documentation for more information about this). This should reset your root password.

然后使用 --init-file 参数启动 mysqld 服务(有关更多信息,请参阅文档)。这应该重置您的 root 密码。

回答by cancerbero

For passing the password in the command use -p$PASSWORD. In the following example, user/password is root/root:

要在命令中传递密码,请使用-p$PASSWORD. 在以下示例中,用户/密码是 root/root:

mysql -proot -D my-db -u root -h 127.0.0.1 -e "select * from my_table"

IMPORTANT: notice that there is no space between -pand the password in -proot

重要提示:请注意,-p密码和密码之间没有空格-proot

回答by luckytaxi

Why don't you specify a password for root? For security reasons and your script would work.

为什么不为root指定密码?出于安全原因,您的脚本将起作用。

回答by tc.

Mysql's "root" account should have a password; otherwise anyone with an account on your machine has full access to the database.

Mysql的“root”账户应该有密码;否则,任何在您机器上拥有帐户的人都可以完全访问数据库。

  1. Set a password(e.g. with SET PASSWORD)
  2. Add the password to ~/.my.cnf
  1. 设置密码(例如使用 SET PASSWORD)
  2. 将密码添加到~/.my.cnf

If you want more sane authentication options, I recommend Postgres.

如果您想要更多合理的身份验证选项,我推荐 Postgres。