mysql8忘记密码
-
查询进程 ps -ef |grep mysql
-
杀死进程
- kill -9 [进程id] 或 systemctl stop mysqld
-
跳过权限 启动
/usr/local/mysql/bin/mysqld --skip-grant-tables --port=13306 --socket=/usr/local/mysql/socket/mysql13306.sock &
-
另起会话登录
- 执行 mysql -u root --port=13306 --socket=/usr/local/mysql/socket/mysql13306.sock
- 修改密码
bashmysql> FLUSH PRIVILEGES; mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'uz@2024#uz'; mysql> exit;
-
正常启动mysql
- 杀死之前的mysql进程 [参照步骤一步骤二]
- 重新启动 mysql
systemctl start mysqld
-
使用更改后的root密码登录并创建用户
cd /usr/local/mysql/bin/
./mysql -u root --port=13306 --socket=/usr/local/mysql/socket/mysql13306.sock -p
bashmysql> CREATE USER 'mysql_uz'@'%' IDENTIFIED BY 'UZ@2024'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'mysql_uz'@'%'; mysql> exit;