I want to connect to MySQL. Unfortunately target server is accessible only from localhost. It is able to work around for example by uploading some PHP script on the server? I mean a single file rather than the entire PHPMyAdmin or something similar.
can you please elaborate more about your issue?
If you want to connect to mysql server remotely then you need to grant user in mysql users table with your local system IP range.
You could look at using ssh to tunnel the connection through your local host .. Will need to know a bit about your network layout
http://www.howtogeek.com/howto/ubuntu/access-your-mysql-server-remotely-over-ssh/
ssh -L 3306:localhost:3306 geek#webserver.com
you can use ssh tunneling for that here is a link
ssh -L 3306:localhost:3306 root#remote-mysql
The syntax is
ssh -L <localport>hostname<remoteport> <username>#<servername>.
We’re using localhost as the hostname because we are directly accessing the remote mysql server through ssh. You could also use this technique to port-forward through one ssh server to another server.
Related
is there a valid extension for connect mysql via ssh on visual code studio?
I can't find nothing!;
I've been tryed with Mysql managment tool but seem there are not options for ssh
I guess you mean that you want to connect to MySQL via an SSH tunnel.
I don't know any specific solution for visual studio code, but if you have an extension to browse your database (and it doesn't support SSH tunneling) on its own, you can just create a ssh tunnel by yourself. Just run:
ssh -L 3306:127.0.0.1:3306 user#remotehost
And keep that session opened for the time you want to use your DB. Point your DB browser at 127.0.0.1:3306 and that's it.
Keep in mind that 127.0.0.1 in the example is the host you're tunneling TO, so if your MySQL server listens on, say, 1.3.3.7, just do -L 3306:1.3.3.7:3306.
I have a ubuntu 16.04 on which I run 3 servers from virtualbox (a webserver, a home file server and a mysql server).
In this mysql server I naturally have an internal ip (192.168....) and an external one.
However when I try to connect remotely to this mysql server from mysql shell, workbench or .NET connector (eg. mysql -u root -p -h 172.241.442.12) using the external IP of this virtual machine I always get ERROR: Not connected.
My question is whether to connect I have to enable port forwarding in my router (3306), just as I would do enabling 80/8080 in a webserver to make it accessible from the internet.
I never did it before and haven't find any clear tutorial either. My main purpose is to connect to this db in a vb.net application.
Thanks!
Yes, if you intend to access it in this manner you will need to forward a port. You will also need to grant access to MySQL for a user that is allowed remote access.
GRANT ALL ON somedb.* TO `user`#`123.123.123.123` IDENTIFIED BY 'somePassword'
The IP address can be a hostname, or % to match everything.
That said, unless you really need a permanant external connection to MySQL you should not expose it like this, the better option would be to tunnel the port through SSH.
ssh -N user#dbserver -L12345:localhost:3306 &
mysql -u root -h localhost -P 12345
I am trying Peewee to connect and retrieve data from a MySQL remote database, but I get the following error:
InternalError: (1130, "Host 'x.x.x.x' is not allowed to connect to this MariaDB server")
Could you help me?
"retrieve data from a MySQL remote database"
"Host is not allowed to connect to this MariaDB server"
Seem to point on a simple problem:
You're not allowed to connect on the DB from "outside".
By default, MySql / MariaDB are only listening on the "inside" of the server, from MariaDb doc :
MariaDB packages bind MariaDB to 127.0.0.1 (the loopback IP address) by default as a security measure using the bind-address configuration directive.
This mean apart for an application that run on the same machine (accessing 127.0.0.1 or localhost), you'll not be able to connect.
Solutions:
SSH tunnelling
This is probably the safest way to allow a connexion on a remote DB.
SSH is a protocol that allow you to connect to a server. It's mainly used on unix server to manage them, but can do a lot more.
How to use it in your case?
if you can connect with SSH to your DB server, then running this simple command on your notebook the will do the trick:
ssh -L 3306:localhost:3306 user#x.x.x.x
Lets explain a bit: first, your run SSH, then, you tell him to enable a port forwarding from your 3306 port to the localhost:3306 port of the server you connect through user#IP.
With this command running, every query from your local machine:3306 will by send to your MariaDB:3306 server, allowing you to use it as if you where on the server.
Allowing a remote-access user
This one is way more dangerous than the previous one. You'll need to take your time and think about every outcome it mean.
As already said, you're not allowed to connect from outside, ssh let you be "inside", but if you know what you do, you can just remove the security.
The point is:
to make an account that'll be able to login from a remote IP,
allow MariaDB to listen on external requests,
and at least, secure other account to disable remote connection.
[I'm not putting the how-to now, if you really need it, I'll update this answer]
I ma following this tutorial on how to connect to a remote MySQL server, however It seems the command doesn't work and often results in Operation timed out when trying to connect to the server:
ssh mysql.xxxxx.com
I can connect directly from my hosting account but not through the Shell on my Mac OS.
There may be a firewall or other network security device in place that prevents you from being able to connect from your Mac. Also, it is possible that the MySQL server is not configured to allow inbound network connections.
You might ask your hosting provider if they filter access to the MySQL port (default is 3306), or if your host is pre-configured with a firewall, and you might check your MySQL configuration file to ensure it is listening for inbound connections.
When you ssh into a remote server, and you do not specify a user name, ssh defaults to your current user.
bobs-macbook-pro:~ bob$ ssh server.acme.com
is the same as:
bobs-macbook-pro:~ bob$ ssh bob#server.acme.com
Try using your username when 'sshing' into the remote mysql machine.
There are two ways to specify your username, either one should work.
1. bobs-macbook-pro:~ bob$ ssh bob#server.acme.com
2. bobs-macbook-pro:~ bob$ ssh server.acme.com -l bob
I have a ubuntu server which I've locked down to only HTTP, HTTPS and SSH (port 30000). On this box I have a MySQL server which 99.9% of the time is only used locally. Every now and then I want to connect to the MySQL instance with the GUI tools, but without touching the firewall.
Therefore, it is possible to set things up so that I can connect to the MySQL box with the SSH connection? Is there any sort of port forwarding magic I can do?
ssh -L localport:127.0.0.1:remoteport user#remotehost
where localport is an unbound port on your local system, remoteport is the port on which MySQL listens, 127.0.0.1 is the loopback address on your remote system, user is your user name and remotehost is the address of the remote system.
Then point your MySQL client to 127.0.0.1:localport. The connection will be forwarded over the SSH tunnel to the remote port.
If you are using Windows or Unix on your local machine, PuTTY is an excellent tool for this. Here's a tutorial on port forwarding:
http://www.cs.uu.nl/technical/services/ssh/putty/puttyfw.html
Set up a tunnel using the SSH client to map a local port, through the tunnel, to a port on the remote machine, then connect to the local port using the client.
man ssh will have the gory details, but you're probably better off searching the web for something a wee bit easier to read.
I'd suggest using HeidiSQL if you are on Windows. It handles the SSH tunnel by itself (you just need to download the plink.exe utility).
In my humble opinion, it is the best MySQL tool out there (and it's free and open source).
There two ways to use the GUI mysql tools on a remote MYSQL machine.
I'm assuming the remote machine is running linux.
Option 1.
SSH port forwarding.
ssh -L 3306:proxy:3306 username#remotehost
Basically you forward port 3306 on your local machine to 3306 on your remote machine, then you tell your graphical MYSQl tool to connect to localhost:3306 and you assume that your remote machine is listening on the standard port of 3306
http://magazine.redhat.com/2007/11/06/ssh-port-forwarding/
Also ssh -D 3306 username#remotehost should be similar
Option 2.
If you are running xserver on your remote machine and have the GUI tools installed on your remote machine you can tunnel your GUI over the SSH connection.
ssh -X username#remotehost and then start your GUI tools over on remote machine from the command line.
SSH/HTTP tunneling in SQLyog is good. There is public/private key authentication which adds an additional layer of security.
I suggest looking to phpMyAdmin a web based tool to administrate MySQL, and is very good (requires PHP). It can be installed through the normal Ubuntu methods (e.g. Synaptic)
Or do X tunnelling with SSH as mentioned above.