Allow setting of MySQL Database Remote Access Permissions

Source: Internet
Author: User

 

1./cd

/Usr/local/mysql/bin

./Mysql-h localhost-u root

// You can access the MySQL server.

2. mysql> GRANT ALL

Privileges on *. * TO 'root' @ '%' WITH GRANT OPTION

// Grant data access permissions to any host

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' WI

TH www.2cto.com

Grant option;

If you want to allow myuser to connect to the mysql server from a host whose ip address is 192.168.1.6, and use mypassword as the password

GRANT

All privileges on *. * TO 'myuser' @ '192. 168.1.3 'IDENTIFIED

'Mypassword'

With grant option;

3. mysql> FLUSH

PRIVILEGES

// The modification takes effect.

  

Mysql> EXIT

 

4. Modify iptables to open the Mysql port to allow remote access

Modify the firewall configuration file: vi

/Etc/sysconfig/iptables Add the following line:-A RH-Firewall-1-INPUT-m state

-State NEW-m tcp-p tcp-dport 3306-j ACCEPT

If you want to activate ports such as 21, you only need to replace 3306 with the ports to be opened, such as 21. After configuration, restart iptable service

Iptables restart can access Mysql from other machines. Note:-A RH-Firewall-1-INPUT-m

State-state NEW-m tcp-p tcp-dport 3306-j ACCEPT-

RH-Firewall-1-INPUT-j REJECT-reject-with icmp-host-prohibited-

RH-Firewall-1-INPUT-j REJECT-reject-with icmp-host-prohibited

It indicates that icmp access is denied. If other packets are returned, a host cannot be accessed. The 3306 error is returned.

The port line must be before icmp-host-prohibited.

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.