修改mysql的root密码

用了好几次了这个方法。记一下:

 

 一、在不知道root密码的情况下,强行修改root密码:

1、停止Mysql

/etc/init.d/mysql stop

或者(根据安装配置的位置不同,而不同)

/etc/init.d/mysqld stop

 

2、进入Mysql安全模式

 mysqld_safe --user=mysql --skip_grant_tables --skip_networking &

在安全模式下:输入

mysql -u root mysql

mysql> update user set password=password('密码') where user='root';

或者 

update user set authentication_string=password('密码') where user='root';

mysql>flush privileges;

mysql>quit;

 

3、重启mysql

/etc/init.d/mysql restart

或者(根据安装配置的位置不同,而不同)

/etc/init.d/mysqld restart

 

4、用新密码登陆试试

mysql -u root -p

 

 

二、在能登录Mysql的情况下,修改root密码

1、修改root密码

mysql>set password for root@localhost = password('123456'); 

 

2、我本地的phpmyadmin出现“拒绝被访问”的情况

(1)进入phpmyadmin的目录:

我的phpmyadmin目录: E:\wamp\apps\phpmyadmin4.1.14

(2)找到config.inc.php

$cfg['Servers'][$i]['verbose'] = 'mysql wampserver';
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '123456';   #### 只修改了这一块的密码

 

posted @ 2017-05-25 18:17  素还真1990  阅读(198)  评论(0)    收藏  举报