Mysql 8.X 忘记密码登录

#操作前先停止mysql
[root@sl local]# service mysqld stop
Shutting down MySQL.. SUCCESS! 

#进入到bin目录下
[root@sl local]# cd /usr/local/mysql/bin/

#忽略密码登录
[root@sl bin]# mysqld --shared-memory --skip-grant-tables
2020-08-24T02:28:50.250886Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-08-24T02:28:50.251042Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) starting as process 17044
2020-08-24T02:28:50.254363Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2020-08-24T02:28:50.254402Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-08-24T02:28:50.254858Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.

#启动mysql
[root@sl bin]# cd /usr/local/mysql/
[root@sl mysql]# service mysqld start

#估计是因为忽略了mysql无密码登录,差这个依懒什么的所以无法正常登录了
[root@sl mysql]# mysql -u root -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

#差什么,哪就装什么呗 
[root@sl mysql]# yum install libtinfo.so.5
Loaded plugins: aliases, changelog, downloadonly, fastestmirror, kabi, presto, security, tmprepo, verify, versionlock
Loading support for CentOS kernel ABI
Loading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ncurses-libs.i686 0:5.7-4.20090207.el6 will be installed
--> Processing Dependency: ncurses-base = 5.7-4.20090207.el6 for package: ncurses-libs-5.7-4.20090207.el6.i686
--> Running transaction check
---> Package ncurses-base.x86_64 0:5.7-3.20090208.el6 will be updated
--> Processing Dependency: ncurses-base = 5.7-3.20090208.el6 for package: ncurses-term-5.7-3.20090208.el6.x86_64
--> Processing Dependency: ncurses-base = 5.7-3.20090208.el6 for package: ncurses-libs-5.7-3.20090208.el6.x86_64
---> Package ncurses-base.x86_64 0:5.7-4.20090207.el6 will be an update
--> Running transaction check
---> Package ncurses-libs.x86_64 0:5.7-3.20090208.el6 will be updated
---> Package ncurses-libs.x86_64 0:5.7-4.20090207.el6 will be an update
---> Package ncurses-term.x86_64 0:5.7-3.20090208.el6 will be updated
---> Package ncurses-term.x86_64 0:5.7-4.20090207.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                   Arch                                Version                                          Repository                         Size
========================================================================================================================================================================
Installing:
 ncurses-libs                              i686                                5.7-4.20090207.el6                               base                              249 k
Updating for dependencies:
 ncurses-base                              x86_64                              5.7-4.20090207.el6                               base                               61 k
 ncurses-libs                              x86_64                              5.7-4.20090207.el6                               base                              245 k
 ncurses-term                              x86_64                              5.7-4.20090207.el6                               base                              546 k

Transaction Summary
========================================================================================================================================================================
Install       1 Package(s)
Upgrade       3 Package(s)

Total download size: 1.1 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 1.1 M
(1/4): ncurses-base-5.7-4.20090207.el6.x86_64.rpm                                                                                                |  61 kB     00:00     
(2/4): ncurses-libs-5.7-4.20090207.el6.i686.rpm                                                                                                  | 249 kB     00:00     
(3/4): ncurses-libs-5.7-4.20090207.el6.x86_64.rpm                                                                                                | 245 kB     00:00     
(4/4): ncurses-term-5.7-4.20090207.el6.x86_64.rpm                                                                                                | 546 kB     00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   707 kB/s | 1.1 MB     00:01     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : ncurses-base-5.7-4.20090207.el6.x86_64                                                                                                               1/7 
  Updating   : ncurses-libs-5.7-4.20090207.el6.x86_64                                                                                                               2/7 
  Updating   : ncurses-term-5.7-4.20090207.el6.x86_64                                                                                                               3/7 
  Installing : ncurses-libs-5.7-4.20090207.el6.i686                                                                                                                 4/7 
  Cleanup    : ncurses-term-5.7-3.20090208.el6.x86_64                                                                                                               5/7 
  Cleanup    : ncurses-libs-5.7-3.20090208.el6.x86_64                                                                                                               6/7 
  Cleanup    : ncurses-base-5.7-3.20090208.el6.x86_64                                                                                                               7/7 
  Verifying  : ncurses-libs-5.7-4.20090207.el6.x86_64                                                                                                               1/7 
  Verifying  : ncurses-term-5.7-4.20090207.el6.x86_64                                                                                                               2/7 
  Verifying  : ncurses-base-5.7-4.20090207.el6.x86_64                                                                                                               3/7 
  Verifying  : ncurses-libs-5.7-4.20090207.el6.i686                                                                                                                 4/7 
  Verifying  : ncurses-libs-5.7-3.20090208.el6.x86_64                                                                                                               5/7 
  Verifying  : ncurses-term-5.7-3.20090208.el6.x86_64                                                                                                               6/7 
  Verifying  : ncurses-base-5.7-3.20090208.el6.x86_64                                                                                                               7/7 

Installed:
  ncurses-libs.i686 0:5.7-4.20090207.el6                                                                                                                                

Dependency Updated:
  ncurses-base.x86_64 0:5.7-4.20090207.el6               ncurses-libs.x86_64 0:5.7-4.20090207.el6               ncurses-term.x86_64 0:5.7-4.20090207.el6              

Complete!

#安装依懒的包文件后可正常登录了
[root@sl mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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>

#因为修改了mysql数据库配置文件无密码登录,所以这里修改密码报如下错误:
mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

#刷新一下配置后再进行修改就没问题
mysql> flush privileges;
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.11 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit;
Bye

 

你可能感兴趣的:(Linux,mysql,数据库,linux,运维)