1. Configure the root password for MySQL
By default, MySQL does not have a password and can be accessed directly:
[Email protected] ~]# Mysql-uroot
Below we set the root password:
[Email protected] ~]# mysqladmin-uroot password ' 123456 '
Enter the password when entering (no spaces after P option):
[Email protected] ~]# mysql-uroot-p123456
Restart takes effect
[Email protected] ~]#/etc/init.d/mysqld restart
2. Reset Password
If we forget the password, we need the initialization to reset; Edit the configuration file
[[email protected] ~]# VIM/ETC/MY.CNF//Add the following command
Skip-grant
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A0/wKioL1XpqZDRfZUQAABy0rx_WQs605.jpg "style=" float: none; "title=" 6.png "alt=" Wkiol1xpqzdrfzuqaaby0rx_wqs605.jpg "/>
Restart MySQL service after saving exit
[Email protected] ~]#/etc/init.d/mysqld restart
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A3/wKiom1Xpp2yy9WeRAACLoIyW1s8397.jpg "style=" float: none; "title=" 7.png "alt=" Wkiom1xpp2yy9weraacloiyw1s8397.jpg "/>
[[email protected] ~]# mysql-uroot//re-enter no password required
mysql> use MySQL//using MySQL Library
mysql> Update user Set Password=password (' 654321 ') where user= ' root '; Update table (change password)
Mysql>quit
Then locate the/ETC/MY.CNF configuration file and delete the previous skip-grant command
Restart takes effect
[Email protected] ~]#/etc/init.d/mysqld restart
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A0/wKioL1XprNPyv4UQAAJnOAZPRDY881.jpg "title=" 8.png " alt= "Wkiol1xprnpyv4uqaajnoazprdy881.jpg"/>
3. Set Remote Login
First to authorize the client
Mysql> Grant All on * * to ' root ' @ ' 192.168.0.104 ' identified by ' 123aaa ';
Query OK, 0 rows affected (0.01 sec)
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A0/wKioL1XpsVvwtde9AADGOBw6VIY274.jpg "title=" 9.png " alt= "Wkiol1xpsvvwtde9aadgobw6viy274.jpg"/>
Note: 192.168.0.104 is the client's IP, login password: 123aaa
Let's test the log in.
[Email protected] ~]# MYSQL-UROOT-H192.168.0.104-P3306-P123AAA
(Log in Success):
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/A0/wKioL1XpsmeCoAL_AAKRNf5-zuU178.jpg "title=" 10.png "alt=" Wkiol1xpsmecoal_aakrnf5-zuu178.jpg "/>
We can view the current user
Mysql> Select User ();
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A0/wKioL1XpsvjCzIcWAACSnZ8QSgc406.jpg "title=" 11.png "alt=" Wkiol1xpsvjczicwaacsnz8qsgc406.jpg "/>
Sometimes there may be multiple databases on the server, and on the server we can log in using sock
[Email protected] ~]# mysql-uroot-s/tmp/mysql.sock-p654321
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A0/wKioL1Xps7Wyr51GAAJ_FU-dN3k795.jpg "title=" 12.png "alt=" Wkiol1xps7wyr51gaaj_fu-dn3k795.jpg "/>
MySQL password setup and reset, and remote login database