我实际上丢失了我的root密码,我需要更改它。我按照以下步骤操作:
步骤1:停止MySQL服务器进程。
步骤2:使用启动MySQL(mysqld)服务器/守护程序进程 --skip-grant-tables选项,以便它不会提示输入密码。
步骤3:以root用户身份连接到MySQL服务器。
我们可以在这些网站上找到:https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords#recover-mysql-root-password
mysql> use mysql;
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("TOOR");
mysql> flush privileges;
mysql> quit
第一个错误,所以我试过了:
mysql> use mysql;
mysql> update user set password=PASSWORD("TOOR") where User='root';
mysql> flush privileges;
mysql> quit
总是同样的错误说:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '("TOO
R") WHERE User='root'' at line 1
我该如何解决这个问题?
答案 0 :(得分:19)
如here所说:
此功能已在MySQL 8.0.11中删除
1。如果您处于跳过授予表模式下
在mysqld_safe中:
UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
exit;
然后在终端:
mysql -u root
在mysql中:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
2。不在跳过授予表模式下
只是在mysql中:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
答案 1 :(得分:8)
Jus使用sudo登录mysql
Sudo mysql
然后
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
exit;
测试
mysql -u root -p
答案 2 :(得分:0)
尝试一下:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPasswd';
答案 3 :(得分:0)
第1步:在根目录中创建一个新文件(例如C :) 步骤2:将此 ALTER USER'root'@'localhost'标识为'abc'并保存 步骤3:如果您的Mysql服务已经在运行,请停止此操作并打开CMD 步骤4:转到您的Mysql安装目录(例如C:\ Program Files \ MySQL \ MySQL Server 8.0 \ bin),然后输入以下命令
mysql --init-file=C:/init.sql
第5步:执行此命令,一切就好了:)
有关更多说明,请参见此视频:https://www.youtube.com/watch?v=LsdV-7dFOhk
答案 4 :(得分:0)
我使用的是 8.0.23,但有多个问题。以下是问题和解决方案。 我遵循了 mysql 文档并能够进行重置,尽管我有问题。我提供了我的解决方案和示例重置脚本。
问题
解决方案
在脚本中,我将root重置为New%Password
# create password reset file
cat << EOF >/tmp/deleteme
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'New%Password';
EOF
# create /var/run/mysqld
mkdir /var/run/mysqld
chown mysql:mysql /var/run/mysqld
# start mysqld and run the command
mysqld --init-file=/tmp/deleteme --user=mysql &
# wait for sql to start
while [ ! -f /var/run/mysqld/mysqlx.sock.lock ]; do sleep 1; done
sleep 3
# stop sql
mysqladmin -u root -pNew%Password shutdown
while [ -f /var/run/mysqld/mysqlx.sock.lock ]; do sleep 1; done
#clean up temp file
rm /tmp/deleteme
答案 5 :(得分:0)
如果您使用的是 Windows,您可以尝试以下步骤
MySQL 8.0
服务cmd
mysqld --console --skip-grant-tables --shared-memory
cmd
mysql -u root
select authentication_string,host from mysql.user where user='root';
UPDATE mysql.user SET authentication_string='' WHERE user='root';
cmd
。在 https://gist.github.com/pishangujeniya/0f839d11a7e692dadc49821c274a2394
找到了这个答案 6 :(得分:-1)
使用SQLYog可以执行命令
用户创建
xxxxx
授权
CREATE USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d'
在MySQL 8.0中更改密码
GRANT ALL PRIVILEGES ON sakila.* TO 'tester'@'localhost'
或者如果您知道authentication_string直接将其设置为更新
ALTER USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d';
在较低版本的mysql中更改密码
UPDATE mysql.user
SET authentication_string='*F9B62579F38BE95639ACB009D79427F2D617158F'
WHERE USER='root'