MySQL password setup and reset, and remote login database

Source: Internet
Author: User


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

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.