Page 1 of 1
Wordpress can't see db
Posted: Wed Jun 20, 2007 9:05 pm
by intellivision
The environment is my local machine, Mac OS X 10.4, mysql 4.x (I think).
Code: Select all
// ** MySQL settings ** //
define('DB_NAME', 'newdb'); // The name of the database
define('DB_USER', 'root'); // Your MySQL username
define('DB_PASSWORD', ''); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
Those are the WordPress config settings that are not working. I get
Error establishing a database connection ...
I can use those same credentials to log in to MySql/localhost using MySql Query Browser.
The DB is running. I've tried restarting Apache and MySql to no avail.
Any thoughts?
Posted: Wed Jun 20, 2007 9:14 pm
by Benjamin
Might need to turn on old_passwords in my.cnf.
It's running on the default port: 3306 and everything?
PHP may not have the MySQL extensions installed.
Posted: Wed Jun 20, 2007 9:23 pm
by intellivision
Thanks for you help, astions.
Mmmm I don't see anything regarding mysql extensions:
mysql
Active Persistent Links 0
Active Links 0
Client API version 4.1.22
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib/mysql -lmysqlclient
Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off
Googling how to enable the extension now...
Posted: Wed Jun 20, 2007 9:27 pm
by Benjamin
If that is from phpinfo, then php has MySQL enabled.
Have you created a database called newdb?
Posted: Wed Jun 20, 2007 9:30 pm
by intellivision
Ok, thanks.
Yup, the db exists, and I'm running mysql on port 3306. I'm checking on old_passwords in my.cnf now...
Posted: Wed Jun 20, 2007 9:52 pm
by intellivision
I added the second line here to my.cnf
then restarted mysql.
Still no luck. I created a table in the db using mysql query browser just to make sure root had privileges, and it does.
Posted: Wed Jun 20, 2007 9:58 pm
by Benjamin
I would download phpMyAdmin and see if it is able to connect to the database. Not sure what else the problem could be. The wordpress error is vague. Do you know how to write a short script that will connect to the db?
Posted: Wed Jun 20, 2007 10:01 pm
by Benjamin
Throw this in a PHP file with your info entered in..
Code: Select all
<?php
if (!is_resource(($dbcon = mysql_connect($host, $user, $pass))))
{
echo "MySQL said: Error: " . mysql_errno() . ' - ' . mysql_error();
} else {
echo "MySQL OK";
}
Posted: Wed Jun 20, 2007 10:14 pm
by intellivision
Code: Select all
<?php
$host='localhost';
$user='root';
$pass='';
if (!is_resource(($dbcon = mysql_connect($host, $user, $pass))))
{
echo "MySQL said: Error: " . mysql_errno() . ' - ' . mysql_error();
} else {
echo "MySQL OK";
}
?>
yields
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Users/matth/Sites/php/index.php on line 7
MySQL said: Error: 2002 - Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)
Posted: Wed Jun 20, 2007 10:24 pm
by Benjamin
Posted: Wed Jun 20, 2007 10:30 pm
by bdlang
Does the socket /var/mysql/mysql.sock exist? Does your php.ini point to the correct socket?
Have you tried using this syntax to specify the port:
Code: Select all
$dbconn= mysql_connect($host .':3306', $user, $pass);
Have you tried connecting via the 'mysql' command line?
Have you verified your MySQL version? What version of PHP?
And yeah, what
astions said.
Posted: Wed Jun 20, 2007 10:45 pm
by intellivision
Looks like my.cnf file had nothing in it (except old-passwords flag that I just put in), and I think that's the culprit. I didn't realize it should be populated with configurations until I started messing around with mysql Administrator.
I activated the port setting by clicking on the write/no write pencil icon in this image:
http://img472.imageshack.us/img472/8434/mysqlwu2.png
Then I saw when I activated the port setting it wrote to my.cnf file.
I'd use that app to configure mysql, but I'm not sure what the settings should be. Can you suggest where to go to get one that's generally configured for simple localhost testing/dev?
Posted: Wed Jun 20, 2007 11:25 pm
by bdlang
Your MySQL distribution should already have several my.cnf option files to choose from. I usually use the 'my-medium.cnf' file and just rename it 'my.cnf'. You can find more information on the config files
here.
Posted: Thu Jun 21, 2007 12:01 pm
by intellivision
Got it. It was a Mac-specific issue. More:
http://docs.info.apple.com/article.html?artnum=302977
Changed:
Code: Select all
mysql.default_socket = /var/mysql/mysql.sock
To:
Code: Select all
mysql.default_socket = /tmp/mysql.sock
in /etc/php.ini. I appreciate all the help you guys offered.