I am unable to use MySQL due to a "refused connection" - php

I am trying to run the no-install version of MySQL on Windows XP located in C:/mysql/ on my machine.
The error message I receive within a PHP file when I try to connect to MySQL reads.
Could not connect: No connection could be made because the target machine actively refused it
I have edited the config file my.ini and altered/added the following.
[client]
port = 3306
socket = C:/mysql/tmp/mysql.sock
[mysqld]
port = 3306
socket = C:/mysql/tmp/mysql.sock
basedir = C:/mysql/
datadir = C:/mysql/data/
bind-address = 127.0.0.1
skip-networking
enable-named-pipe
When I run mysqld.exe I can confirm it is running within command prompt tasklist.
However when I try cmd netstat -a I cannot see any port usage at 3306.
Inside MySQL error logs, it reads.
140411 13:30:34 [Note] c:\mysql\bin\mysqld.exe: ready for connections.
Version: '5.5.37-log' socket: '' port: 0 MySQL Community Server (GPL)
The port: 0 doesn't look correct to me, but I am not sure.
When I run mysql.exe direct in cmd I get the following returned
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
Some things I have tried already.
Placing a copy of my.ini in C:/WINDOWS and also a copy within C:/mysql
Changing bind-address = 127.0.0.1 to bind-address =
localhost
Inside PHP file MySQL connection variants, localhost, 127.0.0.1, 127.0.0.1:3306 inside basic mysql_connect()
Created tmp/mysql.sock file (in case dir + file not existing matters)
Commented out skip-networking in my.ini
After running mysqld.exe whilst running ran mysqladmin.exe in cmd which returns 'Can't connect to MySQL server at 'localhost'
Running telnet localhost 3306 returns
'Connecting To localhost...Could not open connection to the host, on port 3306: C
onnect failed'
Commented out bind-address in my.ini to allow default settings.
Ran mysqld.exe with user root (-u root) also inserted user = root in my.ini
Set Windows Firewall to off.
Thanks in advance.

Ok. You have binded your server to specific ip so please read this MySQL bind-addres. Please unbind your server and check if you have proper user. (last paragraph in documentation)

Related

ERROR 2003 (HY000) while trying to connect to mysql remotely

I am trying to connect to mysql remotely. Because this is such a common question I read several tutorials/questions but I keep getting this error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'the-ip-address' (60)
I edited the /etc/mysql/my.cnf and commented the line of bind_address like this:
#bind-address = 127.0.0.1
After that I ran:
$ sudo service mysql restart
with the output of:
mysql stop/waiting
mysql start/running, process 9853
mysql is running on default port: 3306
Using the user with which I am trying to connect remotely is working locally on the server (I can connect to the mysql from the server).
In phpmyadmin I configure these users:
user#localhost
user#127.0.0.1
user#87.45.34.23
Then I am trying to connect with the following:
mysql -u user -p -h 87.45.34.23
Maybe I am missing something... Thank you in advanced
UPDATE
As #Geoffrey suggested in the comments the problem was with a firewall. For this reason I will accept his answer although the answer itself is not for that but in the comments he was right.
Connection refused means the MySQL server is not listening or is firewalled.
By commenting out the bind line, MySQL doesn't bind to anything and only allows local socket access, you need to bind it to either the local IP, or all IPs by specifying 0.0.0.0
Also ensure that skip-networking is not set anywhere.

Xamp - mysql (3306 error)

Problem detected!
14:26:36 [mysql] Port 3306 in use by ""C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" xxx (PROJECT NAME)"!
14:26:36 [mysql] MySQL WILL NOT start without the configured ports free!
I can't shake this error. Xamp Apache runs great, but can't figure out how to get mysql running.
I tried:
Change php.ini:
mysql.default_port=3307
mysqli.default_port=3307
and my.ini:
[client]
# password = your_password
port = 3307
socket = "C:/xampp/mysql/mysql.sock"
[mysqld]
port= 3307
I don't want to uninstall Mysql workbench (as it has important dbs)
Additional information (I've Installed mysql workbench - not sure if this helps or not)
You could use netstat -lp | grep 3306 to find out what program is already listening on port 3306 (you should see PID/Program name in last column) and stop that (maybe mysql is already running?).
Alternatively you could start the newly installed server on a different port. (edit my.cnf and change the default port there)

connect remotly to mysql server

I want to connect to mysql server remotly .in the local host there is no problem. I check my.conf file but bind-address line and skip-networking no exist in the my.conf .this is my my.conf :
[mysqld]
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
when connect to mysql server from another server this error message displayed :
SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'mysite.com' (13)
I add this line to my.conf :
bind-address= 0.0.0.0
and then restart mysql server but problem still exist .also I turn off firewall with iptables.
I think the problem is about port.default port is 3306. I try to change default port to 8806 but after change port mysql server does not start .
this problem take my time for several day. Can anyone help me?

Apache on Debian server to connect to extern mysql

I have servers :
a Sql server
a VPS
I installed apache on my debian server.
I want to access my SQL server through PDO.
But an error occurs :
SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'my_sql_server_ip' (110)'
However, I can access my SQL server from local apache server (MAMP).
So I think the problem is client side.
Any suggestion ?
On MAMP , click File Menu > Edit Template > MySQL my.cnf
and change bind-address = 127.0.0.1 by bind-address = 0.0.0.0
(don't edit directly /Applications/MAMP/tmp/mysql/my.cnf because MAMP will overwrite the file on restart)

Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

When i connect my database by a php script it shows
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
the username and password is right.
something of the my.cnf
[client]
#password = your_password
port = 3306
socket = /data/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /data/mysql/mysql.sock
skip-external-locking
ps: i change it to socket = /var/lib/mysql/mysql.sock the php script still says "/var/lib/mysql/mysql.sock"?. then run
mysqladmin -u root -p status
it shows
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
service mysqld restart
mysqld: unrecognized service
Q: Does your my.conf still says "/var/lib/mysql/mysql.sock"?
Q: Does the directory "/var/lib/mysql" exist?
Q: Does your mysql user (or better, mysql group) have writer permission?
If so, please try re-starting mysql and see what happens.
ADDENDUM:
One other thing to try is to create a mysql.sock and explicitly give it permissions:
cd /var/lib
mkdir mysql
touch mysql/mysql.sock
chown -R mysql:mysql mysql

Categories