mysql版本5.1.61-1在REHL5上经测试有效

一)设置mysql用户密码

二)忘记root密码后重置方法

三)添加远程root超级管理帐号

    一、设置mysql用户密码的三种方法

  1.[root@localhost]# mysqladmin -uroot -poldpasswd password "newpasswd"

    #若root密码为空也可以

    [root@localhost ~]# mysqladmin -uroot password "newpasswd"

 

  2.[root@localhost ~]# mysql -uroot -p 

     mysql> set password for usernamet@localhost=password('newpasswd');

     #然后刷新授权表

     mysql> flush privileges

  3.[root@localhost ~]# mysql -uroot -p


    mysql> update mysql.user set password=password("newpasswd") where user='username';flush privileges;

    后两种方法把username改为实际用户名即可设置其密码

    第一种方法设置普通用户,需要此用户具有mysql.user的update权限

mysql> create database wang;grant all privileges on wang.* to wang@'%' identified by 'wang';

[root@localhost ~]# mysqladmin -uwang -pwang password "newpasswd"
mysqladmin: Can't turn off logging; error: 'Access denied; you need the SUPER privilege for this operation'

  mysql> grant update on mysql.user to wang@'%' identified by 'wang';

[root@localhost ~]# mysqladmin -uwang -pwang password "newpasswd"

密码修改成功

   二、忘记root密码的重置方法

     [root@localhost ~]# service mysqld stop
     [root@localhost ~]# mysqld_safe --skip-grant-tables&

#屏幕会有输出不理会输入mysql -uroot
[root@localhost ~]#mysql -uroot

#回车可进入mysql,利用上面的第三种方法重设密码

mysql> update mysql.user set password=password("newpasswd") where user='root';
mysql> exit
[root@localhost ~]# service mysqld restart

#重启mysql服务后即可用新密码连接了

#注意:在--skip-grant-tablesx模式下,以下设置root密码方式行不通

mysql> set password for root@localhost=password('newpasswd');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
 

三、添加远程root超级管理帐号

       本地登陆

       [root@localhost ~]# mysql -uroot -p

       mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pwd' WITH  GRANT OPTION;

       mysql> flush privileges;

       mysql>exit