0

I have a mysql database on a remote linux server. I want to access that mysql database from my local pc with a winforms application. But I dont want to give permission to remote connection from server settings using my local ip address.

I am able to connect my local mysql database like this :

        local_builder = new MySqlConnectionStringBuilder();
        local_builder.Server = local_host;
        local_builder.UserID = local_username;
        local_builder.Password = local_password;
        local_builder.Database = local_dbname;
        local_conn = new MySqlConnection(local_builder.ToString() );  

I want to know if there is a way to make a ssh connection to my remote host , then connect to remote db with a code like above using that ssh tunnel .

CS Student
  • 112
  • 1
  • 14
  • you'd need to run a mysql proxy on your remote host. – Garr Godfrey Mar 31 '21 at 22:16
  • 2
    Yes, there is a way-- use ssh port forwarding. If you forward the port MySQL uses, it will just work. You can start the ssh process from your C# program, or get fancy with an OpenSSL library. – antlersoft Mar 31 '21 at 22:17
  • 1
    https://dev.mysql.com/doc/connector-net/en/connector-net-ssh-tunneling.html Seems like a place to start > You can configure SSH tunneling by using either Connector/NET 8.0.17 (or higher) connection-string options or class properties: the MySqlConnectionStringBuilder class for use with classic MySQL protocol or the MySqlXConnectionStringBuilder class for X Protocol. SSH tunnels to MySQL are supported with .NET Framework 4.5.2, .NET Standard 1.3 (.NET Core 1.1), and .NET Standard 2.2 (.NET Core 2.0). – Callistus Asirvatham Mar 31 '21 at 22:20
  • https://stackoverflow.com/questions/10806799/how-to-connect-to-mysql-from-c-sharp-over-ssh – Callistus Asirvatham Mar 31 '21 at 22:23
  • Thanks for all fast replies . I think I will follow @CallistusAsirvatham 's comment. I'll answer my question if I will solve my problem. – CS Student Mar 31 '21 at 22:27
  • https://mysqlconnector.net/tutorials/connect-ssh/ – Bradley Grainger Apr 01 '21 at 15:18

0 Answers0