一,停掉mysql服务
# service mysqld stop
二,修改mysqld_safe的参数
# mysqld_safe --skip-grant-tables --skip-networking
参数解释:
--skip-grant-tables: 绕过授权表,这样就可以在登录mysql时暂时不需要密码。
--skip-networking: 不需要密码即可登录mysql服务器可能会存在安全延缓,因此最好将网络功能关闭。
三,启动mysql服务
# service mysqld start
这样就可以直接登录mysql服务器了
# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.42-log Source distribution Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the buffer. mysql>
四,修改mysql登录密码
mysql> UPDATE user SET PASSWORD=PASSWORD(‘123456‘) WHERE User=‘root‘ AND Host=‘127.0.0.1‘; mysql> UPDATE user SET PASSWORD=PASSWORD(‘123456‘) WHERE User=‘root‘ AND Host=‘localhost‘; mysql> FLUSH PRIVILEGES;
五,把mysqld_safe的参数改回来
# service mysqld stop # mysqld_safe & # service mysqld start # mysql ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
补充:
mysql用户密码修改的常用方法:
1、# mysqladmin -u root -h 127.0.0.1 password ‘123456‘ -p 2、mysql> SET PASSWORD FOR ‘root‘@‘localhost‘=PASSWORD(‘123456‘); 3、mysql> UPDATE mysql.user SET PASSWORD=PASSWORD(‘123456‘) WHERE User=‘root‘ AND Host=‘localhost‘;
时间: 2024-10-11 01:20:07