How can I change root username in MySQL

后端 未结 2 1537
醉话见心
醉话见心 2021-02-05 22:18

I\'m running MySQL in Ubuntu, default installation.

How can I change the username from root to another one, let\'s say admin? Preferably from

相关标签:
2条回答
  • 2021-02-05 22:53

    After connecting to MySQL run

    use mysql;
    update user set user='admin' where user='root';
    flush privileges;
    

    That's it.

    If you also want to change password, in MySQL < 5.7, run

    update user set password=PASSWORD('new password') where user='admin';
    

    before flush privileges;. In MySQL >= 5.7, the password field in the user table was renamed to authentication_string, so the above line becomes:

    update user set authentication_string=PASSWORD('new password') where user='admin';
    
    0 讨论(0)
  • 2021-02-05 23:04

    I just wanted to say that for me, there was no column 'password'.

    To change password, the correct field was authentication_string

    So the command is

    update user set authentication_string=PASSWORD('new password') where user='admin';
    

    I'm no MySQL expert, so I'm not sure exactly why, but what I said is correct, at least in my case.

    0 讨论(0)
提交回复
热议问题