使用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