Mysql5.7 Forget the root password and mysql5.7 modify the root password method _mysql

Source: Internet
Author: User
Tags ssl connection

To close a running MySQL:

[root@www.woai.it ~]# service MySQL Stop

Run

[root@www.woai.it ~]# mysqld_safe--skip-grant-tables &

For security, you can disable remote connections in this way:

[root@www.woai.it ~]# mysqld_safe--skip-grant-tables--skip-networking &

To connect to server using MySQL:

[Root@www.woai.it ~]# Mysql-p

Change Password:

mysql> Update Mysql.user Set Authentication_string=password (' 123qwe ') where user= ' root ' and Host = ' localhost ';

* Special note is that the new version of the MySQL database under the user table has no password field

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

mysql> flush Privileges;
Mysql> quit;

Modification completed. Reboot

[root@localhost ~]# service MySQL restart

And then MySQL will be connected.

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

mysql> alter user ' root ' @ ' localhost ' identified by ' 123 ';

This can also be:

mysql> set password for ' root ' @ ' localhost ' =password (' 123 ');

The key to introduce the MySQL 5.7 root password modification

MySQL Manager password settings or modifications:

According to official instructions after 5.6 version, the first boot will be in the root directory to produce a random password, file name. Mysql_secret.

[Root@bright ~]# cat/root/.mysql_secret
# Password set for user ' Root@localhost ' at 2015-03-27 23:12:10
: Jj+ftiq VYRF
[root@bright ~]# cd/usr/local/mysql/bin/
[root@bright bin]#./mysqladmin-u root-h localhost password ' 123 456 '-P

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

Mysqladmin: [Warning] Using a password on the command line interface can insecure.
Warning:since password would be sent to server in plain text with the use of SSL connection to ensure password.

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

Shell>mysql-uroot-p ' password ' #password即. Mysql_secret password
mysql>set password = password (' newpasswd ');

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

Method One:

Shell>service mysqld Stop #停止mysql服务
shell>mysqld_safe--skip-grant-tables & # To start the MySQL shell>mysql-uroot-p #输入命令回车进入 without enabling Grant-tables mode
, an input password prompt for direct return is present.
mysql>use MySQL;
Mysql>update User Set Password=password ("123456") where user= "root"; #更改密码为 Newpassord
mysql>flush privileges; #更新权限
mysql>quit #退出

Method Two:

Shell>service mysqld Stop #停止mysql服务
shell>mysqld_safe--skip-grant-tables & # To start the MySQL shell>mysql-uroot-p #输入命令回车进入 without enabling Grant-tables mode
, an input password prompt for direct return is present.
mysql > Set password for root@localhost = password (' mysqlroot ');

Method Three:

Shell>/path/mysqladmin-u username-h Host password ' new_password '-p

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.