简体   繁体   English

Mysql 密码已过期,我的 mysql.user 表已损坏

[英]Mysql password expired and my mysql.user table is corrupted

Okay, I have a little problem.好的,我有一个小问题。

My password is expired and my users table is corrupted.我的密码已过期,我的用户表已损坏。 I can login via我可以通过登录

mysql -u root -p 

but on every action I perform I get the folowing error:但是在我执行的每个操作中,我都会收到以下错误:

Column count of mysql.user is wrong. mysql.user 的列数错误。 Expected 45, found 46. The table is probably corrupted.预期为 45,发现为 46。该表可能已损坏。

I have read that you can fix the mysql.user table with the folowing command:我读到您可以使用以下命令修复 mysql.user 表:

mysql_upgrade -u root -p 

But when I do that I get the folowing error:但是当我这样做时,我收到以下错误:

mysql_upgrade: Got error: 1862: Your password has expired. mysql_upgrade:得到错误:1862:您的密码已过期。 To log in you must change it using a client that supports expired passwords.要登录,您必须使用支持过期密码的客户端进行更改。 while connecting to the MySQL server Upgrade process encountered error and will not continue.在连接到 MySQL 服务器时升级过程遇到错误并且不会继续。 So, How do I fix this?那么,我该如何解决这个问题?

I have backups of all my tables so I won't be a problem if I have to reset all my databases.我有所有表的备份,所以如果我必须重置所有数据库,我不会有问题。

(why the weird format? Stackoverflow thinks it's all code and wants me to put it in code blocks, otherwise I can not save it) (为什么是奇怪的格式?Stackoverflow 认为都是代码,要我放在代码块中,否则我无法保存)

EDIT:编辑:

I know my password.我知道我的密码。 That's not the problem at all.这根本不是问题。

My problem is that the password is expired and I am not able to do anything becuase my mysql.user is corrupted!我的问题是密码已过期,我无法执行任何操作,因为我的 mysql.user 已损坏!

Try to disable the password expiration option: edit the my.cnf and put尝试禁用密码过期选项:编辑 my.cnf 并放入

[mysqld]
default_password_lifetime=0

and try to restart mysql server and try again login again.并尝试重新启动mysql服务器并再次尝试登录。 the source is here https://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html来源在这里https://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html

For repairing the database you run mysqlcheck --repair --databases db_name or mysqlcheck --repair --all-databases for repairing all databases The source is here https://dev.mysql.com/doc/refman/5.7/en/rebuilding-tables.html You could first try to repair the database then you could try to disable password lifetime.要修复数据库,请运行mysqlcheck --repair --databases db_namemysqlcheck --repair --all-databases以修复所有数据库 来源在这里https://dev.mysql.com/doc/refman/5.7/en/ rebuilding-tables.html您可以先尝试修复数据库,然后尝试禁用密码生存期。

Had the same issue when restoring an old backup from 2018, reinstalling MySQL as you said in a comment didn't solve the issue.从 2018 年恢复旧备份时遇到同样的问题,如您在评论中所说的那样重新安装 MySQL 并没有解决问题。

How I did:我是怎么做的:

  1. Stop MySQL service停止 MySQL 服务

  2. Run mysqld_safe --skip-grant-tables --skip-networking &运行mysqld_safe --skip-grant-tables --skip-networking &

    (if you get an error you may need to manually create and chown the directory /run/mysqld) (如果出现错误,您可能需要手动创建和 chown 目录 /run/mysqld)

    --skip-grant-tables will allow passwordless logins and will also disable any check on the password expiration --skip-grant-tables 将允许无密码登录,并且还将禁用对密码过期的任何检查

  3. Now run mysql_upgrade --force and mysqlcheck --repair --all-databases现在运行mysql_upgrade --forcemysqlcheck --repair --all-databases

  4. You can now kill the running mysqld_safe ( ps aux | grep mysql to find the PID to kill) and then start the server normally with service mysql start .您现在可以终止正在运行的 mysqld_safe( ps aux | grep mysql以查找要终止的 PID),然后使用service mysql start正常启动服务器。

    In my case it didn't work and I still had the "Expected 45, found 46" error.在我的情况下,它不起作用,我仍然有“预期 45,发现 46”错误。 In that case go ahead:在这种情况下,继续:

  5. Stop the server again and restart it in safe mode as point 2 above再次停止服务器并按照上面的第 2 点在安全模式下重新启动它

  6. Now you should be able to dump the content , but we must exclude the mysql schema from being dumped.现在您应该能够转储内容,但我们必须从转储中排除mysql模式。

    Since mysqldump doesn't have a --exclude-database option, we need to get the list of databases to dump.由于 mysqldump 没有 --exclude-database 选项,我们需要获取要转储的数据库列表。 To get the list of existing databases, except system schemas, run:要获取现有数据库的列表,系统架构除外,请运行:

    mysql -Nse "SELECT GROUP_CONCAT(SCHEMA_NAME SEPARATOR ' ') FROM information_schema.SCHEMATA WHERE SCHEMA_NAME NOT IN ('mysql','information_schema','performance_schema','sys');"

  7. Remove from the list any other db you don't need, and run the dump:从列表中删除您不需要的任何其他数据库,然后运行转储:

    mysqldump --databases db1 db2 ... db50 > mysqldump.sql

  8. Kill mysqld, move the datadir away and create an empty one ( mv /var/lib/mysql /var/lib/mysql-old && mkdir /var/lib/mysql && chown mysql:mysql /var/lib/mysql )杀死 mysqld,将 datadir 移开并创建一个空的( mv /var/lib/mysql /var/lib/mysql-old && mkdir /var/lib/mysql && chown mysql:mysql /var/lib/mysql

  9. service mysql start and a fresh datadir will be populated. service mysql start和一个新的 datadir 将被填充。

  10. Run mysql_secure_installation to set a new root password运行mysql_secure_installation以设置新的 root 密码

  11. Import the dump file: cat mysqldump.sql | mysql -u root -p导入转储文件: cat mysqldump.sql | mysql -u root -p cat mysqldump.sql | mysql -u root -p

After that, the server is UP and running without issues.之后,服务器启动并正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM