linux 系统中mysql密码问题
一、如果忘记密码:
在 /etc/my.cnf 文件的[mysqld]文段下添加 skip-grant-tables 来跳过密码,直接登录mysql;
只需要在命令行输入:mysql ,即可登录
二、修改密码
alter user 'root'@'localhost' identified by 'Wangbi@1';
如果提示:
mysql> alter user 'root'@'localhost' identified by 'Wangbi@1'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql>
则执行:
flush privileges
alter user 'root'@'localhost' identified by 'Wangbi@1';
mysql> flush privileges -> ; Query OK, 0 rows affected (0.00 sec) mysql> alter user 'root'@'localhost' identified by 'Wangbi@1'; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye
然后退出,去掉“skip-grant-tables ”, 重启mysqld ,通过用户名+ 密码登录:
[root@iZwz98th8v1tdszuxpw570Z etc]# systemctl restart mysqld [root@iZwz98th8v1tdszuxpw570Z etc]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2020-12-17 14:06:38 CST; 9s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 2549 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 2573 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─2573 /usr/sbin/mysqld Dec 17 14:06:37 iZwz98th8v1tdszuxpw570Z systemd[1]: Starting MySQL Server... Dec 17 14:06:38 iZwz98th8v1tdszuxpw570Z systemd[1]: Started MySQL Server. [root@iZwz98th8v1tdszuxpw570Z etc]# [root@iZwz98th8v1tdszuxpw570Z etc]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.20 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql