port fowarding for mysql server ubuntu remote connection - mysql

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

Related

mariadb remote connection fail in centos

I have visited many websites for remote connection of MariaDb.
I have executed the command as below to create user with password in sql.
GRANT ALL PRIVILEGES ON . TO 'root#(my server ip)' IDENTIFIED BY '(my password)'
And i've added one line below [mysqld] in the file of /etc/my.cnf.d
bind-address = 0.0.0.0
Then restart MariaDb service as below
sudo systemctl restart mariadb
Everything runs good.
However when i access by below command, it runs failed.
mysql -u root -p -h (my server ip)
I've turn off my firewall in my server, and turn on the port 3306 in GCP server, and it can be expected, i must fail to connect in my local machine.
Since you want to use a TCP connection, I assume that you want to connect to a remote server, not to a server running on the same machine.
Make sure that you are able to connect physically to the database server, e.g. with telnet server_ip:3306.
Determine the IP address of the computer from which you want to connect to the server (= client_ip).
Add a user on the server:
GRANT ... TO root#client_ip
If client and server are running on the same machine, the preferred way is to use a linux socket (user#localhost) which is way faster.

On Django, how to connect to MySQL database on remote server through SSH?

I've looked around, and can't find any answers that specifically address what I'm wondering:
In the Mac terminal, I can access a remote server through ssh:
ssh [my_username]#[server.host.com]
which prompts me for a password, and after I enter my password, it brings me to the remote server.
Once I've logged into the remote server, I can access MySQL:
mysql -u [other_username] -h [mysql.host.com] -p
which prompts me for another password, and after entering the password, I'm in the MySQL console and can show databases located there, etc. We can call the database I'm interested in [database].
My question is, how do I hook up Django, run on my localhost, to [database], so that my app uses that [database]?
You can create an ssh tunnel to map the remote server mysql port to a local port on your machine.
ssh -L 3333:127.0.0.1:<remote mysql port> <username>#<remote host> -N
Whiles this process is active the local port 3333 will connect to the remote port on the remote host.

How to access MySql on my dedicated server from remote machine

I have MySql server setup on my dedicated server with an IP address 12.12.123.123 . I have configured MySql to allow remote access. Now I want to access the server from remote application. How can I do this? How will I get the host/server name of MySql to put in my connection string?
Thanks
You can just put the IP address of the server as the hostname.
Make sure that
The mysql server is listening on the public IP, so in my.cnf:
bind-address = 0.0.0.0
The user you configured on the mysql server is permitted to access the schema remotely:
GRANT ALL PRIVILEGES TO `user`#% ...
To be more secure, you don't have to use the wildcard, you can use a specific host or IP pattern.
Assuming your server is fully accessible and the server instance adequately configured, you can test the connection using mysql's -h switch like so:
mysql -u username -p -h 44.55.66.77
Once this connection has been made successfully, you can use the same details in your application.

How to access mysql of my Webhost from Command Promt

Is it possible to connect mysql of my webhost from cmd on my pc, in the same way as I am connecting to mysql installed on my localhost using XAMPP.
You'll need to download and install the Windows MySQL client
http://www.mysql.com/downloads/installer/
After installation, make sure the mysql executable is in your cmd PATH.
You need to specify the hostname or IP address of the server with the -h parameter.
mysql -u username -p -h myhost.example.com
Yes its possible to connect to MySQL on web host. MySQL runs on port number 3306. You need to check if the web host has this port open. if not you can request your hosting provider to get it opened. Once its done you can connect to MySQL as you do on localhost May be you need to add privileges to user account to connect from remote machine(your localhost IP).
Other option would be to use PhpMyAdmin.

How to access MySQL from a remote computer (not localhost)?

I have my dev environment set up as a Ubuntu Server (with LAMP installation) inside a vmware. The vmware is running on my local windows 7 machine. When I try to access my mysql server via HeidiSQL program the connection fails. I get a:
Server Error 2003, can't connect to mysql server on <IP ADRESS HERE>
I can however access the db server via PhpMyAdmin. MySQL is running and my connection credentials and port are all correct.
I read that you should enter the IPs of the computer you are trying to connect from as the "bind address" in the my.cnf file. Which I did. I tried both the internal network IP as well as the online IP. Still no luck, same message.
Since this isn't a production environment I would ideally like to allow anyone to access that server, not limit it by IP. Especially since my ISP assigns dynamic IPS. So I would have to change it all the time, assuming that even works.
So does anyone know how I can connect to my MySQL server from a remote computer?
P.S. I assume this is something developers have to deal with that's why I posted it here and not Super User. If it must be migrated please send it to Server Fault not Super User.
Ok, be aware this gives the world and his dog access to your mysql server.
GRANT ALL ON *.* to '%'#'%' WITH GRANT OPTION;
But say you are on your home network of 192.168.1.2/16 then you can at least limit it like this.
GRANT ALL ON *.* to '%'#'192.168.%' WITH GRANT OPTION;
Another option is that you have a user and password but want to connect from anywhere
GRANT ALL ON *.* to 'mysecretuser'#'%' IDENTIFIED BY 'mysecretpassword' WITH GRANT OPTION;
first check the ip assigned to vmware using from cmd
ipconfig/all
suppose ipassigned to vmware is 192.168.11.1
now in vmware in ubuntu check the ipadress
ifconfig
suppose ip adress of ubuntu is 192.168.11.137
now open mysql configurations
sudo nano /etc/mysql/my.cnf
change the bind address to ubuntu ip address
bind-address = 192.168.11.137
restart mysql
now connect to mysql
mysql -u root -p
and create a user with all privileges and host ip of vmware i.e 192.168.11.1
GRANT ALL ON db.* TO user#'192.168.11.1' IDENTIFIED BY 'PASSWORD';
now try to connect from windows.
also open port of mysql
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
restart mysql and try to connect on ubuntu host ip address 192.168.11.137
For Heidi SQL I was able to get it to work following the instructions on this article:
http://mysql-tools.com/en/articles/http-tunnel/73-heidisql-a-http-tunnel.html
It uses a program called HTTP Tunnel. It's a lot slower but at least it works. If you use Navicat it comes with a PHP file that you can upload to your server and it will connect via that.