Connecting to a MySQL Server over WAN - mysql

I have setup a MySQL 5.6 Server on an Ubuntu 14.04 Server distribution on Virtualbox, and am trying to connect to it via TCP/IP from the host Linux Mint 17 Desktop OS over the WAN.
Connection through the MySQL client on the VM works fine, but whenever a connection is attempted from the host machine (via mysql-client-5.6 package) an error comes back with one of 2 errors:
INPUT: $ mysql -u client -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
or
INPUT: $ mysql -u client -p protocol=tcp -h 127.0.0.1
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
Server Setup:
Fresh Ubuntu 14.04 Server installation with only mysql-server-5.6 and openssl packages installed from Ubuntu APT repository.
Users created are 'root'#'%' and 'client'#'%', both with full privileges given to them.
Iptables was modified to try and fix the issue (it came completely stripped) and shows: accept tcp connection from mysql and shows:
target: ACCEPT prot: tcp opt: -- source: anywhere destination: anywhere tcp dpt:mysql .
Configuration file "/etc/mysql/my.cnf" was hardly touched, only tried to change bind-address to values 127.0.0.1 , 0.0.0.0 , commented : all unsuccessful. Server and Client socket is set to 3306.
"service mysql status" returns output: "mysql start/running, process 10650"
Checked that tcp port 3306 is being listened to through "netstat -tulpn" command. returns output: PID=tcp6 Local Address=:::3306 Foreign Address=:::* State=LISTEN .
Client Setup:
Installed package mysql-client-5.6 from Ubuntu APT repository
All configurations are preset and untouched.
Would like an affirmation on the following: Was getting the idea that connecting through Unix socket is only possible through the OS hosting the server (internally), while any external OS has to use TCP/IP and so I tried the "protocol=tcp" bit in my 2nd input.
Was searching for a solution for over 2 days now, starting to feel really frustrated. Any useful help would be greatly appreciated!

Related

Nothing will connect to mysql on localhost

I've tried just about everything I can find online. I'm going to try to make a complete list of all of the things that I have tried in no particular order (as it's been about two weeks of hunting for solutions). Where it all starts is my formerly functioning local dev setup was working fine aside from some SQL settings that were interfering with my already established codebase. I found resources online that detailed editing my.cnf file; which I did. From that point forward, nothing will connect to mysql.
1. Uninstall and remove mysql files via terminal
2. Reinstalled mysql and attempted to connect via terminal, didn't work
Running via terminal: mysql -u root
Resulting socket error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
3. Connected to services via DBngin
All services start up and seem to run fine; (Homebrew svcs: php, mysql, httpd). All show a green light and appear to be functioning.
4. Attempt to connect to mySQL via TablePlus
These settings worked before I messed with my.cnf file as described initially (no password):
Host: 127.0.0.1
Port: 3306
User: root
Resulting error: Can't connect to MySQL server on '127.0.0.1' (61)
5. Installed MySQL Workbench / Server, won't connect
Resulting error: SQLSTATE[HY000] [2002] Connection refused
6. Any attempt to load localhost:3306 in Chrome/Safari/Firefox all result in the following
SQLSTATE[HY000] [2002] Connection refused
7. See if mySQL is running
Run in terminal: ps aux |grep mysql
Results in: natashya 74640 0.0 0.0 34132100 908 s002 S+ 1:40pm 0:00.00 grep mysql
Try to kill via: kill 74640
Results in: kill: kill 74640 failed: no such process
Run: brew services restart mysql
Results in: ==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql) ==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
Contents of my.cnf
# Default Homebrew MySQL server config
# Only allow connections from localhost
[mysqld]
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
port = 3306
mysqlx-port = 33060
socket = /var/lib/mysql/mysql.sock
datadir = /usr/local/mysql
tmpdir = /tmp
mysqlx=OFF
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
Thank you so much to Bill Karwin for help. I am however still unable to resolve the site I'm attempting to access (localhost:9000) and get this error: SQLSTATE[HY000] [2002] Connection refused
Redux of the comment thread above:
Check the MySQL Server error log for clues.
The log indicated the directory for the socket files, /var/lib/mysql, did not exist.
Once the directory was created with the right permissions, the MySQL Server process created the socket file.
Also:
ps aux | grep mysql matches the process running grep mysql because the word 'mysql' appears in that command.

Problem with remote connection to MySQL database (Error 1045)

I installed MySQL Server 8.0 on Windows Server 2019, during installation I created user 'superna' # ' %' with DBAdmin rights. When connecting from a local machine, there are no problems (mysql -u superna -p), but when trying to connect from a remote machine (mysql -h 10.165.1.20 -u superna -p), error 1045 is returned.
I checked the availability of port 3306 using nmap, port is open.
When installing mysql server on Windows 10, such problems are not observed, the connection from the remote machine works correctly. Can you tell me what point in the settings I might be missing?
Can you confirm if your my.cnf file have this line? If it hasn't, add it and restart mysql.
bind-address = 0.0.0.0
Problem solved. The server was configured to NAT port 3306 to another machine on the network.

Unable to create a new connection using Navicat in Ubuntu

I have installed XAMPP on my ubuntu. Everything are installed in /opt/lampp directory.
When I run localhost/phpmyadmin, it is working fine and I can create database as well.
But when I try to setup using Navicat, it is returning me
2002 - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")
My server is also running sudo /opt/lampp/lampp start
I have used following configuration:
Host: localhost
Port: 3306
User Name: root
Password: my_password
Can anybody please help me here.
Thank You.
Use 127.0.0.1 ip address instead of localhost to connect to MySQL.
Reason:
When using localhost to connect to MySQL, the operating system will use the socket connector.
If you use the 127.0.0.1 ip address, the operating system will use the TCP/IP connector.

Specifying hostname for MySQL server - connection refused

I deployed a SQL server on my Mac and configured so that root#% has access to it. I also modified my /etc/hosts to have a mapping between my Mac IP (192.168.1.60) and my MySQL server (192.168.1.60 mysql-server). I also added a binding in my.cnf and then restarted the server:
bind-address = 192.168.1.60
port = 3306
However, when I do (from my Mac): mysql -u root -h mysql-server, I can't connect to the MySQL server (and also when I do a "netcat mysql-server 3306", I have this response: nc: connectx to mysql-server port 3306 (tcp) failed: Connection refused).
Any recommendation ?
Many thanks - C

Connecting to MySQL db

When I attempt to connect from Windows 7 using 32bit and 64bit mysql-connector-odbc-5.3.2 and the connectionstring:
Provider=MSDASQL;Driver={MySQL ODBC 5.3 Driver};Server=192.168.1.13;Port=3306;Database=mydb;Uid=root;Pwd=****;
I get
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Likewise with version 5.2.6. After downgrading the provider to 5.1 I get:
[MySQL][ODBC 5.1 Driver]Can't connect to MySQL server on '192.168.1.13' (10060)
which is more encouraging as it has at least recognised the provider.
I have tried adding a firewall rule to allow outbound connections to port 3306. I've tried disabling my local firewall. I have checked that the server is listening on port 3306 and verified the IP address. (tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN) I have further verified that I can access the server and that MySQL is running.
When I attempted to connect using the IP address from an ssh terminal to the server itself:
mysql -u root -h 192.168.1.13 -D whiskeywheel -p
I am prompted for the password after which I get:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.13' (111)
I have added the host/user to the user table in the mysql database and restarted MySQL. I've granted 'ALL' on the database to the user at anyhost ('%') and I've explicitly added access to port 3306 to the ubuntu firewall:
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
I will of course restrict access prior to deployment but I need to be able to interact with the database in a meaningful form while I'm developing it. I'm happy to re install any of the various components and start again as this is early enough in the project but ideally I'd like to know what I've misconfigured or where I went wrong.
mysql server by default only bind to the loopback address on the sever (127.0.0.1). you have to edit the my.cnf file of the server and do a restart of the mysql server.
also note that specifying localhost is treated special by mysql server. it does not call 127.0.0.1 as one would expects.
more info here on how to bind to your external ipaddress:
http://www.cyberciti.biz/faq/unix-linux-mysqld-server-bind-to-more-than-one-ip-address/