After installing mysql, allow remote connection to _ MySQL

Source: Internet
Author: User
After mysql is installed, allow remote connection to bitsCN.com. After mysql is installed, allow remote connection.

Http://blog.sina.com.cn/s/blog_3eba8f1c0100tsox.html

Http://blog.csdn.net/zxyvb/article/details/2462514

Http://www.bitsCN.com/article/31902.htm

After mysql is installed on the virtual machine, check whether the mysql service of the virtual machine is enabled and whether the listening port is 3306.

1 netstat -anp|more

Open the firewall Port 3306

#/Sbin/iptables-I INPUT-p tcp -- dport 3306-j ACCEPT
Then save:
#/Etc/rc. d/init. d/iptables save

View opened ports:
#/Etc/init. d/iptables status

-------------------------------------------------------
Note:

# Disable the firewall
/Etc/init. d/iptables stop
Service iptables stop # stop the service
# View firewall information
/Etc/init. d/iptables status

# Port: 8080
/Sbin/iptables-I INPUT-p tcp -- dport 8080-j ACCEPT
# Restart the firewall to make the changes take effect: (or directly restart the system)
/Etc/init. d/iptables restart
# Save the changes
/Etc/rc. d/init. d/iptables save

In addition, add a line directly in/etc/sysconfig/iptables:
-A RH-Firewall-1-INPUT-m state-state NEW-m tcp-p tcp-dport 8080-j ACCEPT
# Permanently disable the firewall
Chkconfig-level 35 iptables off # this method is originated from the network and is not tested. Therefore, you are not allowed to use this method for security reasons.

ERROR 1130: Host '192. 168.1.3 'is not allowed to connect to this MySQL.

When using a Mysql account for remote login, the following error occurs:
ERROR 1130: Host '192. 168.1.3 'is not allowed to connect to this MySQL

Solution:

1. change the table method (it may be that your account cannot log on remotely, but it can only be on localhost. At this time, you only need to log in to mysql on the computer of localhost, and change the "host" entry in the "user" table in the "mysql" database to "%" from "localhost ")


C:/mysql server 5.1> mysql-u root-p

Enter the password

Mysql> use mysql;

Mysql> show tables; (check whether the table user exists)

Mysql> update user set host = '%' where user = 'root ';

Mysql> quit

Exit mysql

C:/mysql server 5.1> net stop mysql

C:/mysql server 5.1> net start mysql

Now you can remotely connect to this mysql server.

C:/mysql server 5.1> mysql-h 192.168.1.3-u root-p

2. authorization law
For example, if you want myuser to use mypassword to connect to the mysql server from any host.

Grant all privileges on *. * TO 'myuser' @ '%' identified by 'mypassword' with grant option;
If you want to allow myuser to connect to the mysql server from a host whose ip address is 192.168.1.3, and use mypassword as the password
Grant all privileges on *. * TO 'myuser' @ '192. 168.1.3 'identified BY 'mypassword' with grant option;

How to remotely connect to mysql

I have a mysql database on the server and remotely access it. I don't want to announce the root account. so I created a demo account that allows the demo account to access the shandong database in the mysql database anywhere.
Solution 1:
Run the following command on the machine where mysql is installed:
1: Create a user
The code is as follows:
Create user demo identified by 123456"

2,
The code is as follows:
Mysql> grant all privileges on shandong. * TO 'demo' @ '%' WITH GRANT OPTION
// Grant the data access permission to any host. you can also perform the following operations:
Grant all privileges on shandong. * TO 'demo' @ '%' identified by '000000' with grant option;

3,
The code is as follows:
Mysql> FLUSH PRIVILEGES
// The modification takes effect.

4,
The code is as follows:
Mysql> EXIT
// Exit the MySQL server so that you can log on to any other host as a demo.

Reference
In addition, when a client is used to connect to mysql, the connection fails. it seems that you need to re-authorize the user. The procedure is as follows:
[Root @ cicro108 mysql] # bin/mysql-uroot-p-h 127.0.0.1-A cws3
Enter password:
Welcome to the MySQL monitor. Commands end with or/g.
Your MySQL connection id is 1863 to server version: 4.1.20-standard
Type 'help; 'or'/h' for help. type'/C' to clear the buffer.
Mysql> grant all privileges on *. * to root @ "%" identified by "mysql ";
Query OK, 0 rows affected (0.17 sec)
After the permission is changed, the remote connection is still not available, but you can use the following operations.
Mysql> grant all privileges on *. * to root @ "%" identified by "mysql" with grant option;
Query OK, 0 rows affected (0.17 sec)
At this moment, the root user can be remotely connected. of course, other non-root users can also be remotely connected here.

Solution 2:
MySQL 1130 error solution:
This error occurs when you connect to MySQL through MySQL-Front or MySQL administrator.
ERROR 1130: Host ***. *** is not allowed to connect to this MySQL server
This indicates that the connected user account does not have the permission for remote connection and can only log on to the local machine (localhost.
You need to change the host entry in the user table of the MySQL database.
Rename localhost as %

Specific steps: log on to MySQL
Use MySQL first;
An error occurs when the update method is provided by others.
MySQL> update user set host = '%' where user = 'root ';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'primary'
Then, you can view the host information of the database 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 following command:
The code is as follows:
MySQL> flush privileges;

Connect to MySQL administrator !!

BitsCN.com

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.