修改mysql数据库账户和密码

…衆ロ難τιáo~ 提交于 2020-01-14 04:40:26

修改数据库密码

更改密码

  • 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版本没有password这个字段了,password字段改成了authentication_string,所以会出现 Unknown column 'password' in 'field list'这个错误提示。

解决方法

在cmd登陆你的MySQL,然后输入
update mysql.user set authentication_string=password('****') where user='root';
****是你自定义的密码。
然后
flush privileges即可。
重启mysql

更改用户名

  • mysql -u root -p
  • Enter password:***
    选择数据库
    mysql> use mysql;
  • Database changed
    将用户名为root的改为新用户名

mysql> update user set user="新用户名" where user="root";

刷新权限
mysql> flush privileges;
mysql> exit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!