I am using mysql and i am not able to install drupal.

At the page top:
Warning: PDO::__construct(): [2002] Invalid argument (trying to connect via unix://) in /opt/lampp/htdocs/drupal7dev/includes/database/database.inc on line 324

In the red box:
In order for Drupal to work, and to continue with the installation process, you must resolve all issues reported below. For more help with configuring your database server, see the Installation and upgrading handbook. If you are unsure what any of this means you should probably contact your hosting provider.

Failed to connect to your MySQL database server. MySQL reports the following message: SQLSTATE[HY000] [2002] Invalid argument.

* Are you sure you have the correct username and password?
* Are you sure that you have typed the correct database hostname?
* Are you sure that the database server is running?

For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.

Comments

dbeall’s picture

sometimes you have to edit the settings.php file and manually enter the database information:

* Database URL format:
* $db_url = 'mysql://username:password@localhost/databasename';
* $db_url = 'mysqli://username:password@localhost/databasename';
* $db_url = 'pgsql://username:password@localhost/databasename';
*/
# $db_url = 'mysqli://username:password@localhost/databasename';
# $db_prefix = '';

Remove the #'s to turn on the setting

And the database has to be setup, assuming you have that part.

DizzyC’s picture

Googling around for a solution i found this: http://blog.obsidianproject.co.uk/2009/09/php-pdo-and-localhost.html

So at the install screen of Drupal 7 where you have to configure the database settings (where this error comes up) you just have to expand the 'Advanced' section on the bottom and replace 'localhost', the default setting with 127.0.0.1.
Assuming of course your mysql server is on localhost.
Maybe it has something with DNS not resolving 'localhost' to 127.0.0.1?
No clue...

Hope it helps somebody though.

Cheers!

jivmuk’s picture

This worked just fine for me! Thanks much DizzyC!

safaali’s picture

127.0.0.1 worked for me on xampp for linux ubunto 10.10
tx man!

miket3’s picture

Thanks.. that worked for me and Drupal7/xampp

dbeall’s picture

The advanced section is for the database location if it is something other than localhost.
I only have one host that uses localhost, but all the other hosts that I use have something like accountsupportmysql.com -and- onelakesidewebmysql.com
The location of the database can be found on the phpmyadmin screen.
One one install using xamp, I had to use the network IP for the database location 196.168.1.100

mattcbaker’s picture

I actually had to put some debug in to the code to see the SQLSTATE message - for me the page was just returning to the database entry screen and telling me to check the errors and try again, but not actually showing any errors.

A search online found this:
http://stackoverflow.com/questions/1435445/error-on-creating-connection-...

And so having edited:
/opt/lampp/etc/php.ini

And changed:
pdo_mysql.default_socket=
to:
pdo_mysql.default_socket=/opt/lampp/var/mysql/mysql.sock

And restarted xampp, the installation proceeded, with the database host still set to its default of 'localhost'. There's an advantage to doing it that way if you are going to install drupal several times, to save you changing it during the installation procedure.

xampp: 1.7.3a
drupal: 7.0-alpha5

Cheers,

Matt.

ericdfields’s picture

Worked for me too.

… why?

localhost is definitely set up and pointing to 127.0.0.1………

vannus’s picture

127.0.0.1 fixed it for me - cheers!