MySQL root password change

前端 未结 22 2813
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 18:30

I have been trying to reset my MySQL root password. I have run the mysqld_safe --skip-grant-tables, updated the root password, and checked the user table to make sure it is

相关标签:
22条回答
  • 2020-11-29 18:36

    On Ubuntu,

    sudo dpkg-reconfigure mysql-server-5.5 
    

    Replace 5.5 with your current version and you will be asked for the new root password.

    0 讨论(0)
  • 2020-11-29 18:37

    stop all wamp services , exit from wamp.

    open notepad then type> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');

    then save it to c: drive with any name .. like this "c:/example.txt"

    now goto your "wamp" falder wamp > bin > mysql > mysql(your version) > bin in my case path is "C:\wamp\bin\mysql\mysql5.6.17\bin"

    now copy your path then run cmd with (ctrl + r) then type "cmd" (enter)

    type cd then right click on cmd and paste path (enter) now type (mysqld --init-file=C:\example.txt) without braces then (enter)

    then restart PC or open taskmgr and kill mysqld.exe

    start wamp and your password will be removed...

    0 讨论(0)
  • 2020-11-29 18:39

    On MySQL 8.0.4+

    To update current root user:

    select current_user();
    set password = 'new_password';
    

    To update other user:

    set password for 'otherUser'@'localhost' = 'new_password';
    

    To set password policy before updating password:

    set global validate_password.policy = 0;
    set password = 'new_password';
    set password for 'otherUser'@'localhost' = 'new_password';
    

    Other / better way to update root password:

    mysql_secure_installation
    

    Want to stick with 5.x authentication so you can still use legacy apps?

    On my.cnf

    default_authentication_plugin = mysql_native_password
    

    To update root:

    set global validate_password.policy = 0;
    alter user 'root'@'localhost' identified with mysql_native_password by 'new_password';
    
    0 讨论(0)
  • 2020-11-29 18:39

    For MacOS users, if you forget your root password, @thusharaK's answer(https://stackoverflow.com/a/28601069/5628856) is good, but there are a little more tricks:

    If you are using system preference to start mysql serverside, simply

    sudo mysqld_safe --skip-grant-tables
    

    might not work for you.

    You have to make sure the command line arguments is same with system start config.

    The following command works for me:

    /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so --skip-grant-tables
    

    You can use

    ps aux | grep mysql
    

    to check your own.

    0 讨论(0)
  • 2020-11-29 18:40

    So many coments, but i was helped this method:

    sudo mysqladmin -u root password 'my password'
    

    In my case after instalation i had get mysql service without a password for root user, and i was need set the password for my security.

    0 讨论(0)
  • 2020-11-29 18:41

    This is the updated answer for WAMP v3.0.6 and up

    > UPDATE mysql.user 
    > SET authentication_string=PASSWORD('MyNewPass') 
    > WHERE user='root';
    
    > FLUSH PRIVILEGES;
    

    In MySQL version 5.7.x there is no more password field in the mysql table. It was replaced with authentication_string. (This is for the terminal/CLI)

    UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE user='root';
    
    FLUSH PRIVILEGES;
    

    (This if for PHPMyAdmin or any Mysql GUI)

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