MYSQL+SSH Configuration (reprint)

Source: Internet
Author: User
Tags ssh port

MYSQL+SSH Configuration


I. MYSQL+SSH configuration between Linux platforms

The local address is: 192.168.189.133
MySQL server address is: 192.168.189.139


SSH tunnel under linux command line using SSH command
Generate SSH Public key on this machine and copy to MySQL server


Raw-Cost machine id_rsa.pub file with ssh-keygen command
# Ssh-keygen Continuous carriage return to generate Id_rsa.pub file

Copy the Id_rsa.pub file to the MySQL server
# ssh-copy-id-i ~/.ssh/id_rsa.pub 192.168.189.139

Digging a tunnel on this machine
Use the SSH command to open a 3388 port on this machine, this port is the entrance port of the tunnel, by connecting this port on the local computer to reach the MySQL server 3306 port.
Use the following command:
SSH-NCPF [email protected] -L 3388:192.168.189.139:3306

Parameter interpretation

-C uses the compression function, which is optional and speeds up.
-P connect out with a non-privileged port.
-F Once SSH completes the authentication and establishes the port forwarding, it is run in the background.
-N does not execute the remote command. This parameter is useful when opening a forwarding port only (V2 version SSH support)

Here [email protected] is the SSH user name and IP address of the login MySQL server-l 3388:192.168.189.139:3306
This parameter means that the mapping of the 3388 port to the 192.168.189.139:3306 port is open in this machine, that is to say, the tunnel entrance is 3388 egress for the MySQL server 3306

If an error occurs:

The error is: The authenticity of host 192.168.0.xxx can ' t be established.

Perform Ssh-o stricthostkeychecking=no 192.168.0.xxx on OK

PS: This seems to be used to avoid input for the first time to execute SSH requirements for revenue yes/no.


View local connection condition after execution  
[[email protected] ~]# NETSTAT-TULNP | grep 3388 
tcp         0      0 127.0.0.1:3388               0.0.0.0:*                    listen      3076/ssh             
tcp        0       0::1:3388                    :::*                          listen       3076/ssh  

View the SSH connection between this computer and the MySQL server
[Email protected] ~]# Netstat-an | grep 192.168.189.139
TCP 0 0 192.168.189.133:43489 192.168.189.139:22 established

With these two commands, after executing the command, the computer and the MySQL server established an SSH connection, and opened 3388 ports.

Need to empower the local server on the MySQL server (permissions are self-determined)
GRANT SELECT on * * to ' FC ' @ ' 192.168.189.133 ' identified by ' 111111 ';

Connect a MySQL server locally through a tunnel
[Email protected] ~]# mysql-ufc-p 3388-h 127.0.0.1-p111111
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 30
Server Version:5.1.48-log Source Distribution

Copyright (c), Oracle and/or its affiliates. All rights reserved.
This software comes with absolutely NO WARRANTY. This is the free software,
And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Test |
+--------------------+
4 rows in Set (0.00 sec)

Test success

Because the server restarts the tunnel will fail
This local tunnel needs to be added to the/etc/rc.d/rc.local.
SSH-NCPF [email protected] -L 3388:192.168.189.139:3306

Ii. Client connection of Windows platform to MySQL server on Linux

Specific Settings Reference http://holy2010.blog.51cto.com/1086044/518431

Connect MySQL on Linux with Navicat for MYQL

The method is very simple as long as the software set SSH this function can be

General options to fill in the information for the local database
SSH option in use SSH tunnel fill in the remote Linux account and password can be, SSH port 22
Test Connection

This article is from the "Holy" blog, make sure to keep this source http://holy2010.blog.51cto.com/1086044/518499

--------------------------------------------------------------------------------------------------------

Personal Summary:

Host: MySQL Database

Sub-machine: Establish SSH tunnel

Native: Navicat for MySQL access host database

1. Log on to MySQL set permissions on the host computer, set the permissions of the secondary IP (refer to: http://www.cnblogs.com/hfdp/p/6088288.html)

2. SSH tunnel to host on the secondary machine

3. Local access:

Submit the database address of the secondary machine login host port account password and so on, and login the IP account password (port 22, the machine to the host SSH tunnel end eloquence is 3388)

MYSQL+SSH Configuration (reprint)

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.