Mysql5.7 forgot root Password and mysql5.7 change the root password method

Source: Internet
Author: User
Tags administrator password

Transferred from: http://www.jb51.net/article/77858.htm

To close a running MySQL:

?
1 [[email protected] ~]# service mysql stop

Run

?
1 [[email protected] ~]# mysqld_safe --skip-grant-tables &

For security, you can disable remote connections like this:

?
1 [[email protected] ~]# mysqld_safe --skip-grant-tables --skip-networking &

To connect to server using MySQL:

?
1 [[email protected] ~]# mysql -p

Change Password:

?
1 mysql> updatemysql.user set authentication_string=password(‘123qwe‘) where user=‘root‘ andHost = ‘localhost‘;

* Note that there is no password field in the user table in the new MySQL database.

Instead, the encrypted user password is stored in the Authentication_string field

?
12 mysql> flush privileges;mysql> quit;

The modification is complete. Restart

?
1 [[email protected] ~]# service mysql restart

And then MySQL can connect.

But at this point the operation seems to be incomplete, but also alter user ...

?
1 mysql> alteruser ‘root‘@‘localhost‘ identified by‘123‘;

This also allows you to:

?
1 mysql> setpassword for‘root‘@‘localhost‘=password(‘123‘);

Focus on the MySQL 5.7 root password modification

MySQL Administrator password settings or modifications:

According to the official note 5.6 Later, the first boot will produce a random password, the file name, in the root directory. Mysql_secret.

?
12345 [[email protected] ~]# cat/root/.mysql_secret # Code class= "SQL keyword" >password set for user ' [email protected] ' at 2015-03-27 23:12:10 :JJ+FTIQVYRF [[email protected] ~]# cd/usr/ local /mysql/bin/ [[email protected] bin]#./mysqladmin-u root-h localhost password ' 123456 ' -p

Enter Password: #此行输入. Second line in Mysql_secret

?
12 mysqladmin: [Warning] Using a passwordon the command line interface can be insecure.Warning: Since password will be sent to server in plain text, use ssl connection to ensure passwordsafety.

The official way, the author whether or not to use--skip-grant-tables to start MySQL test failed, the pro can test:

?
12 shell>mysql -uroot -p‘password‘#password即.mysql_secret里的密码mysql>SET PASSWORD= PASSWORD(‘newpasswd‘);

Old version, after installation root no password, as follows:

Method One:

?
1234567 shell>service mysqld stop #停止mysql服务shell>mysqld_safe --skip-grant-tables & #以不启用grant-tables模式启动mysqlshell>mysql -uroot -p #输入命令回车进入,出现输入密码提示直接回车。mysql>use mysql;mysql>update user set password=PASSWORD("123456")where user="root"; #更改密码为 newpassordmysql>flush privileges; #更新权限mysql>quit #退出

Method Two:

?
1234 shell>service mysqld stop #停止mysql服务shell>mysqld_safe --skip-grant-tables & #以不启用grant-tables模式启动mysqlshell>mysql -uroot -p #输入命令回车进入,出现输入密码提示直接回车。mysql > setpassword for[email protected] = password(‘mysqlroot‘);

Method Three:

?
1 shell>/path/mysqladmin -u UserName -h Host password‘new_password‘-p

Mysql5.7 forgot root Password and mysql5.7 change the root password method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.