Centos6.5 Reset the MySQL password and set the Allow remote connection

Source: Internet
Author: User
Tags mysql login


Root password forgotten, reset the root password of MySQL:

First, modify the MySQL configuration file my.cnf

1. In paragraph [mysqld], add one sentence: skip-grant-tables

[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-name-resolve
Skip-grant-tables
Save and Exit VI.

(or executive Mysqld_safe--skip-grant-tables &)

2. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]


3. Log in and modify the root password of MySQL
#/usr/bin/mysql
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3 to server version:3.23.56
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.

mysql> use MySQL;
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a

Database changed
mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows matched:2 changed:0 warnings:0

mysql> flush Privileges;
Query OK, 0 rows affected (0.01 sec)

Mysql> quit
Bye
4. Change the MySQL login settings back
# VI/ETC/MY.CNF
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.

5. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]


Two

Stop MySQL Service

/etc/init.d/mysqld stop

sudo mysqld_safe--skip-grant-table&

Mysql

Use MySQL;

Update user Set Password = password (' yourpasswd ') where user = ' root ';

Flush privileges;

Restart the MySQL service to re-login with the new password

/etc/init.d/mysqld restart


Allow remote connection to MySQL

This error that occurs when you connect to MySQL via Navicat
ERROR 1130:host ***.***.***.*** isn't allowed to connect to this MySQL server
Indicates that the connected user account does not have remote connection permissions and can only log on natively (localhost).
You need to change the host entry in the user table in the MySQL database
Rename localhost to%

One

Login to MySQL, first use MySQL;
There was an error when the update was provided in the other way.
mysql> Update user set host= '% ' where user = ' root ';
ERROR 1062 (23000): Duplicate entry '%-root ' for key ' PRIMARY '
The host information for the following database is then viewed as follows:
Mysql> Select host from user where user = ' root ';
+-----------------------+
| Host |
+-----------------------+
| % |
| 127.0.0.1 |
| Localhost.localdomain |
+-----------------------+
3 Rows in Set (0.00 sec)
The host already has the% value, so run the command directly:

Mysql>flush privileges;


Two

Mysql> Grant all privileges on * * to ' root ' @ '% ' withgrant option;

Query OK, 0 rows affected (0.02 sec)


mysql> flush Privileges;

Query OK, 0 rows Affected (0.00 sec)


Mysql> selectuser.host from user;

+-----------+--------------+

| user| Host|

+-----------+--------------+

| Root| %|

| Root| 127.0.0.1|

| Repl_user | 192.168.1.52 |

+-----------+--------------+

3 Rows in Set (0.00 sec)

Allow specified IP access to MySQL

Mysql> Grant all privileges on * * to ' root ' @***.***.***.**** identified by ' 123456 ';
Queryok, 0 rows Affected (0.00 sec)

Centos6.5 Reset the MySQL password and set the Allow remote connection

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.