Home >Database >Mysql Tutorial >How to use SSH channel to access mysql

How to use SSH channel to access mysql

王林
王林forward
2020-01-27 20:20:152177browse

How to use SSH channel to access mysql

The method of using SSH channel to connect to remote Mysql is as follows:

1. Establish SSH channel

Just type the following command locally :

ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.com

Recommended online learning video tutorial: mysql video tutorial

2. Connect to Mysql

Now, you can connect locally The remote database is just like accessing the local database.

mysql -h 127.0.0.1 -P 3307 -u dbuser -p db

Or use Mysql Query Brower to access the Client's 3307 port.

Similarly, use PHP to access:

<?php
$smysql = mysql_connect( "127.0.0.1:3307", "dbuser", "PASS" );
mysql_select_db( "db", $smysql );
?>

Recommended related articles and tutorials: mysql tutorial

The above is the detailed content of How to use SSH channel to access mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete