问题复现步骤
Linux 系统安装的MySQL8 重置初始化操作:
- 进入安装目录
/usr/local/mysql
- 删除初始化动作产生的数据文件和日志文件
rm -rf data/*
rm -rf logs/*
- 启动服务失败,并报错
systemctl start mysqld
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2022-04-27 22:03:16 CST; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 6105 ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/conf/my.cnf (code=exited, status=1/FAILURE)
Main PID: 6105 (code=exited, status=1/FAILURE)
修复方案:
- 执行重新初始化数据命令
./bin/mysqld -remove MySQL
./bin/mysqld \
--defaults-file=/usr/local/mysql/conf/my.cnf \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data/ \
--user=mysql \
--initialize
- 记录初始化的密码,后面需要登录服务使用
- 启动服务,并查看服务运行状态成功
systemctl start mysqld
systemctl status mysqld
- 登录MySQL数据库,修改root用户密码和更改权限管理员
mysql -uroot -p'3)Mqpkp&u!.0'
use mysql;
alter user 'root'@'localhost' identified by 'root';
update user set host='%' where user='root';
flush privileges;
问题处理结束,MySQL正常使用