shaf81
asked on
Cannot Start MySQL if my.cnf present
Hello,
I have a mysql server installed (Server version: 5.1.40 MySQL Community Server (GPL) on Fedora 9). Below on the code section you can see the files and the permissions of those files.
I use the command:
/usr/local/mysql/support-f iles/mysql .server start
To start the server. Same is used to stop, by passing the "stop" param.
The problem here is, when I delete the my.cnf file (/usr/local/mysql/my.cnf) (there is no my.cnf in the /etc path), then the Mysql server starts just fine and I can log in to the mysql console. However the problem here is, when I try to access a database using Apache/PHP, I get the Cannot connect via socket error. Thus I realized some config should go into the my.cnf file.
However, the problem is, when I add aa my.cnf file and then try to start mysql, I get the following error:
[root@freebox mysql]# ./support-files/mysql.serv er start
Starting MySQL.Manager of pid-file quit without updating file.[FAILED]
Please check the code section for the my.cnf contents.
I tried commenting / uncommenting socket, pid-file, log-error etc, but mysql never seems to start. I keep getting the same error. However, if I get rid of the my.cnf and start mysql, it just works. Only problem, I cannot connect via apache/php.
How can I fix this. If any more info is needed, please let me know.
Cheers
Shaf
I have a mysql server installed (Server version: 5.1.40 MySQL Community Server (GPL) on Fedora 9). Below on the code section you can see the files and the permissions of those files.
I use the command:
/usr/local/mysql/support-f
To start the server. Same is used to stop, by passing the "stop" param.
The problem here is, when I delete the my.cnf file (/usr/local/mysql/my.cnf) (there is no my.cnf in the /etc path), then the Mysql server starts just fine and I can log in to the mysql console. However the problem here is, when I try to access a database using Apache/PHP, I get the Cannot connect via socket error. Thus I realized some config should go into the my.cnf file.
However, the problem is, when I add aa my.cnf file and then try to start mysql, I get the following error:
[root@freebox mysql]# ./support-files/mysql.serv
Starting MySQL.Manager of pid-file quit without updating file.[FAILED]
Please check the code section for the my.cnf contents.
I tried commenting / uncommenting socket, pid-file, log-error etc, but mysql never seems to start. I keep getting the same error. However, if I get rid of the my.cnf and start mysql, it just works. Only problem, I cannot connect via apache/php.
How can I fix this. If any more info is needed, please let me know.
Cheers
Shaf
[root@freebox mysql]# ll
total 156
drwxr-xr-x 2 root mysql 4096 2009-11-12 02:48 bin
-rw-r--r-- 1 root mysql 19071 2009-10-06 14:21 COPYING
drwxr-x--- 5 mysql mysql 4096 2009-11-12 02:57 data
drwxr-xr-x 2 root mysql 4096 2009-10-06 14:20 docs
-rw-r--r-- 1 root mysql 5139 2009-10-06 14:21 EXCEPTIONS-CLIENT
drwxr-xr-x 2 root mysql 4096 2009-10-06 14:20 include
-rw-r--r-- 1 root mysql 9439 2009-10-06 14:21 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 2009-10-06 14:20 lib
drwxr-xr-x 4 root mysql 4096 2009-10-06 14:20 man
-rw-r--r-- 1 root mysql 342 2009-11-12 03:11 my.cnf
drwxr-xr-x 10 root mysql 4096 2009-10-06 14:21 mysql-test
-rw-r--r-- 1 root mysql 62989 2009-10-06 14:21 README
drwxr-xr-x 2 root mysql 4096 2009-10-06 14:21 scripts
drwxr-xr-x 27 root mysql 4096 2009-10-06 14:21 share
drwxr-xr-x 5 root mysql 4096 2009-10-06 14:21 sql-bench
drwxr-xr-x 2 root mysql 4096 2009-10-06 14:21 support-files
CONTENTS of my.cnf
[root@freebox mysql]# cat my.cnf
[mysqld]
datadir=/var/lib/mysql
socket = /tmp/mysql.sock
[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/tmp/mysqld.pid
I would also suggest that you make the permssions rw-rw---- on my.cnf
Hello,
Please make sure that /var/lib/mysql and /tmp/mysql.sock are owned by mysql.
chown mysql.mysql /var/lib/mysql
chown mysql.mysql /tmp/mysql.sock
Also make sure /tmp/mysql.sock is having full permission. (777)
Please make sure that /var/lib/mysql and /tmp/mysql.sock are owned by mysql.
chown mysql.mysql /var/lib/mysql
chown mysql.mysql /tmp/mysql.sock
Also make sure /tmp/mysql.sock is having full permission. (777)
- make sure datadir=/var/lib/mysql exists.
- socket=/tmp/mysql.sock should be under section [client] and not [mysqld]
- socket=/tmp/mysql.sock should be under section [client] and not [mysqld]
ASKER
Hi,
As advised I have created a mysql.sock file under the /tmp folder, gave ownership to mysql (chown mysql.mysql mysql.sock) and changed permission to 777
I have also edited the my.cnf as shown in the code section (1), Furthermore, my.cnf permission is set to 664, ownership is root:mysql
When I start mysql, it starts fine, and I'm able to login using the mysql console client without a problem. The socket is used properly as specified. See code section (2) for mysqladmin version output.
However, the PROBLEM is- I am unable to connect to mysql via PHP. I get the error:
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)
What I don't understand is, why is PHP mysql_connect() trying to connect to a different socket? What is the problem here? I even tried modifying mysql_connect('localhost:\ tmp\mysql. sock'..... ), but problem still seems to persist.
I really don't understand why things have to be so complicated. What am I doing wrong here? I Just need to get php to connect on the proper socket (/tmp/mysql.sock) now.
Please help.
As advised I have created a mysql.sock file under the /tmp folder, gave ownership to mysql (chown mysql.mysql mysql.sock) and changed permission to 777
I have also edited the my.cnf as shown in the code section (1), Furthermore, my.cnf permission is set to 664, ownership is root:mysql
When I start mysql, it starts fine, and I'm able to login using the mysql console client without a problem. The socket is used properly as specified. See code section (2) for mysqladmin version output.
However, the PROBLEM is- I am unable to connect to mysql via PHP. I get the error:
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
What I don't understand is, why is PHP mysql_connect() trying to connect to a different socket? What is the problem here? I even tried modifying mysql_connect('localhost:\
I really don't understand why things have to be so complicated. What am I doing wrong here? I Just need to get php to connect on the proper socket (/tmp/mysql.sock) now.
Please help.
(1)
[root@freebox mysql]# less my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
skip-networking
skip-innodb
[client]
socket=/tmp/mysql.sock
[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/tmp/mysqld.pid
(2)
[root@freebox bin]# ./mysqladmin version
./mysqladmin Ver 8.42 Distrib 5.1.40, for pc-linux-gnu on i686
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.1.40
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 22 min 29 sec
Threads: 1 Questions: 2 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 0.1
Error seems pointing to something else:
it says "... server through socket '/var/lib/mysql/mysql.sock ' (2)"
while you've provided - mysql_connect('localhost:\ tmp\mysql. sock'..... )
are the slashes a problem? shouldn't it be /tmp/mysql.sock ??
it says "... server through socket '/var/lib/mysql/mysql.sock
while you've provided - mysql_connect('localhost:\
are the slashes a problem? shouldn't it be /tmp/mysql.sock ??
ASKER
the direction of the slash was a typo on my part when typing this question. The problem is, even if i dont ecplicitly specify the socket during mysql_connect() shouldn't it default to the socket specified in the my.cnf [clients] section?
My socket is in /tmp, but the connect function is trying to connect to /var/lib/mysql. Why? How to fix this?
My socket is in /tmp, but the connect function is trying to connect to /var/lib/mysql. Why? How to fix this?
Could you please restart the mysql server and check?
ASKER
Things are really strange on the mysql connectivity. I used the simple php script as shown in code section (1).
The socket is located at /tmp/mysql.sock (as shown in the my.cnf file and mysqladmin version output, above). When I execute the php script, I get the error:
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
I see the script is attempting to connect via the correct socket (/tmp/mysql.sock), however, the connection is failing. Nevertheless, I'm able to connect to mysql via local console.
I've restarted mysql many times, verified the config files, file permissions etc and everything looks okay in my knowledge.
I also tried to telnet to port 3306 from the localhost itself, and the output is shown in code section (2). I wonder if that says something?
Please help.
The socket is located at /tmp/mysql.sock (as shown in the my.cnf file and mysqladmin version output, above). When I execute the php script, I get the error:
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
I see the script is attempting to connect via the correct socket (/tmp/mysql.sock), however, the connection is failing. Nevertheless, I'm able to connect to mysql via local console.
I've restarted mysql many times, verified the config files, file permissions etc and everything looks okay in my knowledge.
I also tried to telnet to port 3306 from the localhost itself, and the output is shown in code section (2). I wonder if that says something?
Please help.
(1)
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
(2)
[root@freebox html]# telnet localhost 3306
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
3)
[root@freebox bin]# ./mysqladmin version
./mysqladmin Ver 8.42 Distrib 5.1.40, for pc-linux-gnu on i686
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.1.40
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 9 min 23 sec
Threads: 1 Questions: 6 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 0.10
(4)
[root@freebox bin]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.40 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
- http://dev.mysql.com/doc/refman/5.0/en/can-not-connect-to-server.html.
- http://dev.mysql.com/doc/refman/5.0/en/problems-with-mysql-sock.html.
- Remove socket=/tmp/mysql.sock from [mysqld] section of my.cnf.
- http://dev.mysql.com/doc/refman/5.0/en/problems-with-mysql-sock.html.
- Remove socket=/tmp/mysql.sock from [mysqld] section of my.cnf.
ASKER
I've read thru all links given in here, I've also tried all suggestions, but the problem just doesn't seem to disappear!
1) MySQL Server is running fine
2) I'm able to connect to mysql server via 'mysql' and 'mysqladmin'
3) I'm NOT able to connect via php.
I tried changing socket locations and removing socket entries from my.cnf files. Everytime, the error seems to be the same, no matter what I do. However, I noticed one small difference, check the below 2 errors:
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
The difference I see here is the number within the parenthesis. (2) & (13), I'm sure these mean something, but what could it be really?
I don't know if the problem is Mysql related, php related or even apache related.
1) MySQL Server is running fine
2) I'm able to connect to mysql server via 'mysql' and 'mysqladmin'
3) I'm NOT able to connect via php.
I tried changing socket locations and removing socket entries from my.cnf files. Everytime, the error seems to be the same, no matter what I do. However, I noticed one small difference, check the below 2 errors:
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
The difference I see here is the number within the parenthesis. (2) & (13), I'm sure these mean something, but what could it be really?
I don't know if the problem is Mysql related, php related or even apache related.
OS error code 2: No such file or directory
OS error code 13: Permission denied
OS error code 13: Permission denied
Check your php.ini once!
ASKER
Well, been digging a little, making changes in a few places, including the php.ini and I believe I have some progress now.
I tried executing the php script via the console, and it seems to connect to the DB without a problem:
[root@freebox bin]# php -f /var/www/html/db_test.php
Connected successfully
However, if I try to execute the same script in the browser, via apache, then I get the following error:
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
Wonder what's going on.
I read somewhere if I made mysql_connect to connect on 127.0.0.1 and NOT localhost, then it would work (due to tcp/ip connections). - but I don't want to do that. I have disabled tcp/ip.
I also read that if you set the apache user and group permissions to mysql, then it would work, I don't believe this to be the correct solution.
So what could possibly be the solution to get this working?
I tried executing the php script via the console, and it seems to connect to the DB without a problem:
[root@freebox bin]# php -f /var/www/html/db_test.php
Connected successfully
However, if I try to execute the same script in the browser, via apache, then I get the following error:
Could not connect: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
Wonder what's going on.
I read somewhere if I made mysql_connect to connect on 127.0.0.1 and NOT localhost, then it would work (due to tcp/ip connections). - but I don't want to do that. I have disabled tcp/ip.
I also read that if you set the apache user and group permissions to mysql, then it would work, I don't believe this to be the correct solution.
So what could possibly be the solution to get this working?
ASKER
Wow! The solution for this problem comes from another post on EE.
https://www.experts-exchange.com/questions/22606034/Can't-connect-to-MySQL-server-through-php-apache-but-command-line-php-works.html
Apparently SELinux is by default enabled on my distro and that's what was causing all these trouble. Had to type- "setenforce 0" and disable SELinux, and Presto! Everything works fine! Gosh, this is crazy!
https://www.experts-exchange.com/questions/22606034/Can't-connect-to-MySQL-server-through-php-apache-but-command-line-php-works.html
Apparently SELinux is by default enabled on my distro and that's what was causing all these trouble. Had to type- "setenforce 0" and disable SELinux, and Presto! Everything works fine! Gosh, this is crazy!
Thanks for letting us know. That is very useful information.
This was new!! SELinux!!!
ASKER
The Solution for this quesiton is the reply ID:25828585
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
port = 3306