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> update mysql. user set authentication_string= password ( ‘123qwe‘ ) where user = ‘root‘ and Host = ‘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> alter user ‘root‘ @ ‘localhost‘ identified by ‘123‘ ; |
This also allows you to:
?
1 |
mysql> set password 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 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. |
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模式启动mysql
shell>mysql -uroot -p #输入命令回车进入,出现输入密码提示直接回车。
mysql>use mysql;
mysql>
update user set password
=
PASSWORD
(
"123456"
)
where user
=
"root"
; #更改密码为 newpassord
mysql>flush
privileges
; #更新权限
mysql>quit #退出
|
Method Two:
?
1234 |
shell>service mysqld stop #停止mysql服务 shell>mysqld_safe --skip-grant-tables & #以不启用grant-tables模式启动mysql shell>mysql -uroot -p #输入命令回车进入,出现输入密码提示直接回车。 mysql > set password 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