在 ubuntu 上忘记 MySQL 用户名

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

Forgotten MySQL username on ubuntu

mysqldatabaseubuntu-12.04usernamegnome-terminal

提问by Ema4rl

I've forgotten my MySQL owner details. I need a way to find my username. My password will not be a problem. I use Ubuntu 12.04 Linux, and would prefer a command line solution.

我忘记了我的 MySQL 所有者详细信息。我需要一种方法来找到我的用户名。我的密码不会有问题。我使用 Ubuntu 12.04 Linux,并且更喜欢命令行解决方案。

Thank you in advance.

先感谢您。

回答by Alma Do

Well, then you have a clear way to restore it:

那么,你有一个明确的方法来恢复它:

  1. Run your MySQL server with skipping grant tablesoption.
  2. Log in as root
  3. Run query

    SELECT DISTINCT user FROM mysql.user
    
  4. That's it - you have a list of users. Save it somewhere, then run server normally and try your user names one by one.

  1. 使用跳过授权表选项运行您的 MySQL 服务器。
  2. 以 root 身份登录
  3. 运行查询

    SELECT DISTINCT user FROM mysql.user
    
  4. 就是这样 - 您有一个用户列表。保存在某处,然后正常运行服务器并一一尝试您的用户名。

Tip: if you want to reset root password, there's a corresponding manual page.

提示:如果你想重置root密码,有相应的手册页

回答by Kārlis Millers

Well there is simple way how to change mysql user password as root

那么有一个简单的方法如何以 root 身份更改 mysql 用户密码

mysql -u root -p password
mysql> SET PASSWORD FOR username = PASSWORD('new_password_here');