Wordpress can't see db

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Wordpress can't see db

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.

Code: Select all

<?php phpinfo();
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

If that is from phpinfo, then php has MySQL enabled.

Have you created a database called newdb?
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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...
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post by intellivision »

I added the second line here to my.cnf

Code: Select all

[mysqld]
old-passwords
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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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";
}
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Here is more information on that error. http://dev.mysql.com/doc/refman/5.0/en/ ... erver.html
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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.
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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?
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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.
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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.
Post Reply