Fork me on Gitee

mysql怎样更改密码和用户名

mysql怎样更改密码和用户名

  • 更改密码(老版本):

    mysql -u root -p
    Enter password:***
    mysql>use mysql; --选择数据库--
    Database changed
    mysql> UPDATE user SET password=PASSWORD("新密码") WHERE user='你的用户名';
    mysql> FLUSH PRIVILEGES;
    mysql> quit;

  • 新安装的MySQL5.7,登录时提示密码错误,安装的时候并没有更改密码,后来通过免密码登录的方式更改密码,输入时

    update mysql.user set password=password('root') where user='root';
    提示

    ERROR 1054 (42S22): Unknown column 'password' in 'field list',

    原来是mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

  • 所以更改语句替换为

    update mysql.user set authentication_string=password('root') where user='root';

  • 更改用户名:

    mysql -u root -p
    Enter password:***
    mysql> use mysql; --选择数据库--
    Database changed
    mysql> update user set user="新用户名" where user="root";
    --将用户名为root的改为新用户名--
    mysql> flush privileges; --刷新权限--
    mysql> exit

  • 更多精彩内容,请关注微信关注公众号 明叶师兄的学堂

posted @ 2018-05-17 23:06  明叶师兄。  阅读(8134)  评论(0)    收藏  举报