mysql root密码忘记了

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

mysql root password forgotten

mysqlpasswordsrootreset

提问by user1187405

I did not use php mysql for quite a while and now I need to use it again.But problem is I forget the password for mysql console.and getting error #1045 when try to login in phpmyadmin. In mysql site I saw a article how to reset root password( http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-windows)

我有一段时间没有使用 php mysql,现在我需要再次使用它。但问题是我忘记了 mysql 控制台的密码。尝试登录 phpmyadmin 时出现错误 #1045。在 mysql 站点中,我看到了一篇如何重置 root 密码的文章(http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-windows

Steps are
create a mysql-init.txt file containing UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root'; FLUSH PRIVILEGES;

步骤是
创建一个 mysql-init.txt 文件,其中包含 UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root'; 同花顺特权;

I saved it as C:\me\mysql-init

我将它保存为 C:\me\mysql-init

and in command prompt I wrote-- C:\wamp\bin\mysql\mysql5.5.8\bin\mysqld --init-file=C:\me\mysql-init.txt

在命令提示符中我写了-- C:\wamp\bin\mysql\mysql5.5.8\bin\mysqld --init-file=C:\me\mysql-init.txt

I tried with double back slashes also..but it is not working.mysql console is asking for password and its not taking the new-one.What am I doing wrong?I have several tables there.what to do? Thanks in advance.

我也试过双反斜杠..但它不起作用.mysql控制台要求输入密码并且它没有使用新的密码.我做错了什么?我有几张桌子.怎么办?提前致谢。

回答by NoodleX

try to start mysql with --skip-grant-tables

尝试使用 --skip-grant-tables 启动 mysql

mysqld --skip-grant-tables
mysqld --skip-grant-tables

then connect to your mysqld without username/password using mysql command line

然后使用mysql命令行连接到没有用户名/密码的mysqld

shell> mysql

shell> mysql

then issue command

然后发出命令

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

回答by Thunder Rabbit

I couldn't get mysqldin Adelave's answer to work. But this worked for me instead

mysqld无法回答 Adelave 的工作。但这对我有用

stop and start mysql with --skip-grant-tables

使用 --skip-grant-tables 停止和启动 mysql

service mysql.server stop
service mysql.server start --skip-grant-tables

then connect to your mysqld without username/password

然后在没有用户名/密码的情况下连接到您的 mysqld

mysql

then update the password on mysql command line

然后在mysql命令行上更新密码

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

then restart mysql normally

然后正常重启mysql

 service mysql.server restart

回答by Rajkaran Mishra

Here are the steps to be followed:

以下是要遵循的步骤:

  1. Locate the MySQL configuration file using: $ mysql --help | grep -A 1 "Default options"
  1. 使用以下命令找到 MySQL 配置文件: $ mysql --help | grep -A 1 "Default options"

enter image description here

在此处输入图片说明

On Ubuntu 16, the file location is typically /etc/mysql/mysql.conf.d/mysqld.cnf

在 Ubuntu 16 上,文件位置通常是 /etc/mysql/mysql.conf.d/mysqld.cnf

  1. Edit the configuration file using: $ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

  2. Add skip-grant-tablesunder [mysqld]block and save the changes.

  1. 使用以下命令编辑配置文件: $ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

  2. skip-grant-tables[mysqld]块下添加并保存更改。

enter image description here

在此处输入图片说明

  1. Restart MySQL service using: sudo service mysql restart

  2. Check MySQL service status: sudo service mysql status

  1. 使用以下命令重新启动 MySQL 服务: sudo service mysql restart

  2. 检查 MySQL 服务状态: sudo service mysql status

enter image description here

在此处输入图片说明

  1. Login to mysql with: $ mysql -u root

  2. And change the rootpassword:

  1. 使用以下命令登录 mysql: $ mysql -u root

  2. 并更改root密码:

mysql> FLUSH PRIVILEGES;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPass';

mysql> 刷新特权;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPass';

  1. Revert back the MySQL configuration file changes by removing skip-grant-tablesline or commenting it with a #(hash).

  2. Finally restart the MySQL service and you are good to go.

  1. 通过删除skip-grant-tables行或用#(散列)注释来恢复 MySQL 配置文件更改。

  2. 最后重启 MySQL 服务,一切顺利。

回答by khaintt

If other answer could not help, you can try to uninstall/re-install mysql. It works on my ubuntu server:

如果其他答案没有帮助,您可以尝试卸载/重新安装 mysql。它适用于我的 ubuntu 服务器:

$sudo apt-get purge mysql*
$sudo apt-get autoremove
$sudo apt-get autoclean

Update distribution

更新分布

$sudo apt-get dist-upgrade

And re-install

并重新安装

$sudo apt-get install mysql-server

回答by chaithanya varma

Using SQLYog you can execute commands

使用 SQLYog 您可以执行命令

  • User Creation
  • 用户创建


CREATE USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d'
  • Authorization
  • 授权


GRANT ALL PRIVILEGES ON sakila.* TO 'tester'@'localhost'
  • Changing Password in MySQL 8.0
  • 在 MySQL 8.0 中更改密码


ALTER USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d'

(or if u know the authentication_string directly set it to update)

(或者如果你知道 authentication_string 直接将其设置为更新)

UPDATE mysql.user 
    SET authentication_string='*F9B62579F38BE95639ACB009D79427F2D617158F'  
WHERE USER='root'***

Changing password in lower versions of mysql

在较低版本的mysql中更改密码

GRANT USAGE ON *.\* TO 'tester'@'localhost' IDENTIFIED BY 'Pass123#d'
SET PASSWORD FOR 'tester'@'localhost' = PASSWORD('Pass123#d');**