使用rpm -ql mysql-community-server
發現並無安裝過mysqld_safe這個文件, 解決方法是換一種重置密碼的方式: 在my.cnf文件的[mysqld]
下面添加skip-grant-tables
選項,重啓mysqld服務便可本機無密碼登陸。mysql
[root@localhost ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
複製代碼
my.cnf的路徑通常是/etc/my.cnf
,不過也有人說是在/usr/my.cnf
sql
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
...
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables # 添加這一行
複製代碼
參考:segmentfault.com/q/101000000…segmentfault