MYSQL connecting from outside network - mysql

i am having trouble connecting to mysql from a outside network. If i were to connect it locally, it can be done. Assuming i'm a host, what should i do?

You need to set up port forwarding in your router on port 3306 to your local IP port 3306. You'll need to grant rights to a user to allow access from external IP.
For example:
CREATE DATABASE Test;
GRANT ALL ON Test.* TO remoteUser#'10.11.12.100' IDENTIFIED BY 'PASSWORD123';
Or all tables:
GRANT ALL PRIVILEGES ON *.* to remoteUser#10.11.12.100 IDENTIFIED BY "PASSWORD123";
If that don't work check your MySQL server settings, Example /etc/mysql/my.cnf (Debian)
Settings file:
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306 - CHECK THAT PORT IS CORRECT
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 1.1.1.1 CHECK THAT IP IS CORRECT
skip-networking = DELETE OR # FRONT OF IT

Port forward your router on port 3306. This is the default port for mysql. Make sure you have the same port open on your server. Make sure your ISP (Internet Service Provider) allows traffic on this port. I would suggest using something like MySQL Workbench http://www.mysql.com/products/workbench/ to manage your database if you don't already.

Related

MySQL port showing close after changing bind-address to server's private address

I am using Digital Ocean's droplet I want to access my database though my workbench. Earlier I was using Google's compute engine with same settings like changing bind-address to server's private-ip and then creating user with same ip as a host. Example
my.cnf
port = 3306
bind-address = 10.223.0.1
mysql user
CREATE USER 'adam'#'10.223.0.1' IDENTIFIED BY 'abc#123';
GRANT ALL PRIVILEGES ON *.* TO 'adam'#'10.223.0.1' WITH GRANT OPTION;
I was able to access this user on my local machine with the use of server's external IP.
But now if I update bind-address with my private IP and check with external port checker tool. it tells me that port 3306 is closed and if I change to 0.0.0.0 than port shows open and I am able to access. But the thing is, I am adding updating private ip as I want to replicate my database to another server. how I can solve this.
Ufw is allowed for 3306 ipv4 ipv6 and droplet firewall have inbound rules for 3306 too
Thank you in advance.
Solved, I created SSH connection tunnel to connect mysql remotely and kept my bind-address as server's private IP.

Connect to remote mysql server from ubuntu fails

I'm using AWS server (ubuntu) for backup my remote mysql db, using mysqldump command.
Since I changed the db password, I cannot connect anymore remotely from the machine using /etc/mysql/my.cnf configuration file.
When I'm using the command
mysql -u root -h 1.1.1.1 -p 123456
It's connects successfully, but when I'm trying to connect by using the mysql configuration file /my.cnf by typing just
mysql
I gets the error message :
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I restarted the db server (I don't need mysql service running on aws because I connected remotely)
I don't want to connect through any socket
my.cnf file content:
[client]
port = 3306
host = 1.1.1.1
user = root
password = 123456
[mysqld]
user = mysql
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = 1.1.1.1
I don't know what have changed, except from the password, I didn't change anything neither in the db itself and in the config file, so I have no idea why it stopped working.
Add in the my.cnf the line protocol=tcp
[client]
port = 3306
host = 1.1.1.1
user = root
password = 12345
protocol = tcp
That force MySQL to use TCP and not the socket connection

Can't connect to remote mysql database server

I can't figure out why i cant access a remote MySQL server in ubuntu inside a VMware. I already have the codes, and it's successfully connecting to my localhost as well as insert, delete and update of data's. But when I make a new connection string with specified IP server address it show an error:
I can only access the files in that server through SSH and browser (192.168.56.xxx/phpmyadmin).
Here's my code for connection string.
Dim conn As New MySqlConnection
conn.ConnectionString = "Server=192.168.56.xxx;port=3306;User=root;password=mypassword;Database=prodDB_vb"
conn.Open()
MessageBox.Show("Connection to Database has been opened.")
cmd.Connection = conn
I already read a lot of forums about this. But dont understand what they are pointing to.
Also i executed the code:
GRANT ALL PRIVILEGES ON prodDB_vb TO 'root#*' IDENTIFIED BY 'my_password';
FLUSH PRIVILEGE;
The only thing i know is that i cannot find the my.cnf in the server files, but already change my my.ini in my localhost's bind ip address.
#bind-address="127.0.0.1"
3306 is listening
And i have this in my my.cnf
Why having this error?
Anyone please help.
Did you check to make sure that MySQL is actually listening on 3306? Run a netstat -tlpn and provide the results. If you don't see 3306 then its probably not.
In my.cnf you should verify that --skip-networking is commented out
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 65.55.55.2
# skip-networking
To locate your CNF file
Edited:
For example, if your MySQL server IP is 192.162.0.3 then entire block should be look like as follows:
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 192.168.0.3
# skip-networking
....
..
....
bind-address : IP address to bind to.
skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should removed from file or put it in comment state.
Then we have to Restart mysql service to take change in effect:
/etc/init.d/mysql restart

MySQL "Unable to connect to host [host] because access was denied."

I'm having an issue connecting remotely to my MySQL server. I know my user is setup with the '%' wildcard from any host, so I should have access to the server. I can log in locally on the MySQL server with my credentials, just not remotely.
My settings in my.cnf look like this:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld]
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#
bind-address = 128.xxx.xxx.xxx
And I'm connecting with the following params (using Coda2 GUI -- but the problem doesn't seem related to Coda2):
Server: 128.xxx.xxx.xxx
Port: 3306
Username: sadmicrowave
Password: my_mysql_password
The full error message posted is:
Unable to connect to host uslonsweb003 because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
MySQL said: Access denied for user 'sadmicrowave'#'128.xxx.xxx.xxx' (using password: YES)
I can telnet to my server using IP address and 3306 so I know the server is listening on that port...
What the heck is going on?
Did you issued the flush privileges after granting access to the wildcard user?
What happens if you add an entry with user = sadmicrowave and host = [your actual ip] (don't forget to issue the flush privileges command after adding the user) ?

Remote Mysql access

I have problem to connect remote LAN MYSQL. While try following commands it shows the following error.
$ mysql -u root -h 192.168.1.15 -p
mysql> GRANT ALL test.* TO root'192.168.1.15' IDENTIFIED BY '';
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.15' (10060)
If you have full access to your server (root privileges required):
Step 1: edit my.cnf (usually located in /etc)
Find the following line: [mysqld] and make sure line skip-networking is commented (or remove line) and add following line:
bind-address=YOUR-SERVER-IP
For example, if your MySQL server IP is 66.166.170.28 then entire block should be look like as follows:
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 66.166.170.28
# skip-networking
.......
Where
bind-address : IP address to bind to.
skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state.
Step 2: Grant access to all hosts
Start the MySQL monitor with this command: mysql or /usr/local/mysql/bin/mysql. Your shell prompt should now look like this: mysql>. Run this command:
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'%' IDENTIFIED BY "PASSWORD";
Where:
USERNAME is the username that you use when connecting using your php script.
PASSWORD is the password you use when connecting.
You now must flush MySQL's privileges. Run this command:
FLUSH PRIVILEGES;
Run this command to exit MySQL:
exit;
Step 3: restart mysql deamon
/etc/init.d/mysqld restart
or
/etc/init.d/mysql restart
depending on what linux distro is your server currently running.
You should also check that your MySQL server has been configured to accept remote TCP connections.
In your MySQL configuration file (my.cnf), you need the following at least:
port = 3306 # Port MySQL listens on
bind-address = 192.168.1.15 # IP address of your server
# skip-networking # This should be commented out to enable networking
The default in some configurations is for the bind-address to be 127.0.0.1, or to skip networking completely, which means only local or unix socket connections are possible. This is for security reasons.
You can also configure the bind-address to be 0.0.0.0 which means it will bind on all IP addresses on the server.
And lastly, check your firewall configuration to allow port 3306.
GRANT ALL ON test.* TO 'root'#'192.168.1.15' IDENTIFIED BY '';
Comment the line below in file /etc/mysql/my.cnf
# bind-address = 127.0.0.1
And add (any)host permission to login(maybe root) on mysql server.
Hard way: you need insert in mysql.host table...
Easy way: use MySQL Administrator->User Administration->Choose user->(Right mouse click)Add host->Select "Any host"
Finally restart server:
/etc/init.d/mysql restart
PS:
Default install aptitude
mysql version: MySQL 5.1.57-1~dotdeb.0
Linux Debian 6 Squeeze
As above, getting rid of "skip-networking" in my.cnf need to be done.
However, on some configurations, that is over-ridden by SKIP="--skip-networking" in a start-up file, such as rc.mysqld. So take that out also.
Does hosts.allow permit one machine to talk to the other in any case?
And leave us not forget the actual documentation.
Just thought I'd throw in another suggestion here...
Some MySQL GUI tools (Sequel Pro for Mac and EMS SQL Manager for Windows) allow MySQL connections through SSH tunnelling. This means you don't have to grant extra privileges. I have found this to be the fastest way of getting remote access to MySQL databases that I administer.