mysql 新用户创建的问题

解决这个错误。

ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

  1. Stop mysql:
    systemctl stop mysqld

  2. Set the mySQL environment option
    systemctl set-environment MYSQLD_OPTS="–skip-grant-tables"

  3. Start mysql usig the options you just set
    systemctl start mysqld

  4. Login as root
    mysql -u root

  5. Update the root user password with these mysql commands
    mysql> UPDATE mysql.user SET authentication_string = PASSWORD(‘MyNewPassword’)
    -> WHERE User = ‘root’ AND Host = ‘localhost’;
    mysql> FLUSH PRIVILEGES;
    mysql> quit

*** Edit ***
As mentioned my shokulei in the comments, for 5.7.6 and later, you should use
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘MyNewPass’;
Or you’ll get a warning

  1. Stop mysql
    systemctl stop mysqld

  2. Unset the mySQL envitroment option so it starts normally next time
    systemctl unset-environment MYSQLD_OPTS

  3. Start mysql normally:
    systemctl start mysqld

Try to login using your new password:
9. mysql -u root -p

在以上的操作过程中会遇到以下问题
ERROR 1396 (HY000): Operation CREATE USER failed for ‘root’@‘localhost’

1
create user ‘root’@‘localhost’ identified by ‘123456’;

2
flush privileges;

3
create user ‘root’@‘localhost’ identified by ‘123456’;

4 如果再次报错
drop user ‘root’@‘localhost’;

5再次创建
create user ‘root’@‘localhost’ identified by ‘123456’;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杜甲同学

感谢打赏,我会继续努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值