1. 停止MySQL
Ubuntu或Debian使用如下命令停止MySQL
sudo /etc/init.d/mysql stop
CentOS或Fedora或RHEL命令:
sudo /etc/init.d/mysqld stop
2. 安全模式
以安全模式启动MySQL,此模式下启动过程中会跳过用户授权表
sudo mysqld_safe --skip-grant-tables & # &不可少
3.登录
mysql -uroot
use mysql;
4. 重设密码
为root用户设定新密码
update user set password=PASSWORD("newpassword") where User='root';
记得要刷新授权
flush privileges;
5. 重启
新密码设定后,先退出MySQL
quit
停止并启动MySQL
在Ubuntu和Debian上
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
在CentOS、Fedora、RHEL上
sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start
6. 新密码登录
mysql -uroot -pnewpassword
7.创建新用户
create user zabbix@localhost identified by ‘zabbix’;
grant all privileges on zabbix.* to zabbix@localhost;
flush privileges;