Mysql5.7 forget the root password and mysql5.7 modify the root password, mysql5.7root

Source: Internet
Author: User
Tags ssl connection

Mysql5.7 forget the root password and mysql5.7 modify the root password, mysql5.7root

Disable running MySQL:

[root@www.woai.it ~]# service mysql stop

Run

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

To ensure security, you can disable remote connection as follows:

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

Connect to the 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';

* Note that the Password field is no longer in the user table of the new mysql database.

Instead, the encrypted user password is stored in the authentication_string field.

mysql> flush privileges;mysql> quit;

Modification completed. Restart

[root@localhost ~]# service mysql restart

Then mysql can be connected.

However, at this time, the operation seems to be not fully functional, but also alter user...

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

You can also:

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

I would like to introduce how to change the mysql 5.7 root password.

MySQL administrator password setting or modification:

According to official instructions for Versions later than 5.6, a random password will be generated under the root directory at the first startup, with the file name. mysql_secret.

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

Enter password: # Enter the second line in mysql_secret.

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

In the official way, no matter whether or not I use -- skip-grant-tables to start mysql, the test fails. You can test it as follows:

Shell> mysql-uroot-p 'Password' # password is the password in. mysql_secret mysql> set password = PASSWORD ('newpasswd ');

If the old version does not have a password after installation, perform the following operations:

Method 1:

Shell> service mysqld stop # stop mysql service shell> mysqld_safe -- skip-grant-tables & # Start mysqlshell> mysql-uroot-p in the grant-tables mode not enabled # enter the command and press ENTER, enter the password and press Enter. Mysql> use mysql; mysql> update user set password = PASSWORD ("123456") where user = "root"; # Change password to newpassordmysql> flush privileges; # update permission mysql> quit # exit

Method 2:

Shell> service mysqld stop # stop mysql service shell> mysqld_safe -- skip-grant-tables & # Start mysqlshell> mysql-uroot-p in the grant-tables mode not enabled # enter the command and press ENTER, enter the password and press Enter. Mysql> set password for root @ localhost = password ('mysqlroot ');

Method 3:

shell>/path/mysqladmin -u UserName -h Host password 'new_password' -p
Articles you may be interested in:
  • MySQL-four methods for modifying the root password (take windows as an example)
  • Resetting mysql root Password (available for test)
  • How to change the root password without restarting Mysql
  • How to change the default mysql null password (root password) in xampp
  • MySQL 5.7 enhanced version Semisync Replication Performance Optimization
  • How to install the latest MySQL version 5.7.9in mac OS X10.10

Related Article

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.