MySQL mysqladmin:连接到“本地主机”服务器失败

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

mysqladmin: connect to server at 'localhost' failed

mysqlubuntu-14.04mysqladmin

提问by udgru

Today (2015-05-02) I upgraded my Linux system via apt-get update and
apt-get upgrade whereas mysql, mysqladmin and a lot more packages
have been updated. The mysql-server-5.5 runs and I can login and do all
the typical database operations but when I type:

今天 (2015-05-02) 我通过 apt-get update 和
apt-get upgrade升级了我的 Linux 系统,而 mysql、mysqladmin 和更多的包
已经更新。mysql-server-5.5 运行,我可以登录并执行所有
典型的数据库操作,但是当我输入:

user@ubuntu:~# mysqladmin proc

I get the following error:

我收到以下错误:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

Formerly I could solve this issue by simple setting the mysql root password new.
This does not solve the issue anymore:

以前我可以通过简单地将 mysql root 密码设置为新来解决这个问题。
这不再解决问题:

user@ubuntu:~# sudo dpkg-reconfigure mysql-server-5.5

How do I get the mysqladmin up again without reinstalling mysql?

如何在不重新安装 mysql 的情况下再次启动 mysqladmin?

回答by Henning Kockerbeck

Short version: If your MySQL user rootneeds a password to connect, it might be a good idea to have mysqladminprovide that password ;)

简短版本:如果您的 MySQL 用户root需要密码才能连接,mysqladmin提供该密码可能是个好主意;)

Longer version: Your MySQL user rootseems to need a password to connect

更长的版本:您的 MySQL 用户root似乎需要密码才能连接

setting the mysql root password new

设置mysql root密码新

But mysqladmintries to connect withouta password

但是mysqladmin尝试在没有密码的情况下连接

'Access denied for user 'root'@'localhost' (using password: NO)'

'用户'root'@'localhost'的访问被拒绝(使用密码:NO)'

And mysqladmindoes that because you're not telling it otherwise ;)

mysqladmin这是否因为你不告诉它,否则;)

mysqladmin, like other MySQL-related command line tools (mysql, mysqldump, mysqlshowetc.), offers options to provide such access data.

mysqladmin像其他MySQL相关的命令行工具(mysqlmysqldumpmysqlshow等),提供选项,以提供这样的访问数据。

  • h: Which host to connect to. If not provided, localhostis assumed
  • u: Which user to connect as. If not provided, rootis assumed
  • p: Which password to use. If not provided, no password is used
  • h: 连接到哪个主机。如果未提供,localhost则假定
  • u: 以哪个用户身份连接。如果未提供,root则假定
  • p: 使用哪个密码。如果未提供,则不使用密码

You should be able to use something like

你应该能够使用类似的东西

mysqladmin -uroot -pmysupersecretpassword proc

(be aware that there's no space between the options and their values). You can also have MySQL ask you for the password like

(请注意,选项与其值之间没有空格)。您也可以让 MySQL 询问您的密码,例如

mysqladmin -uroot -p proc

With that, MySQL should give you a prompt where you can enter your password.

这样,MySQL 应该会提示您输入密码。