i was trying to login to this website I'm trying to create and i got this error:

Connection failed: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

please help me. TIA!

Well that probably means that you have somehow specified the wrong MySQL connect/login data.

EDIT: Ahum, reading the error again, I think there might be something else wrong :p. Although I am not sure what it could be, I still suggest you validate that your connect/login data is correct.

Check if the MySQL daemon is up and if the path to the socket is correct: this is defined in the configuration file of MySQL, i.e. /etc/mysql/my.cnf, in distro-specific configuration files, like /etc/mysql/debian.cnf, and in the PHP configuration file through pdo_mysql.default_socket=.

Cascading rule is applied: the PHP configuration overrides debian.cnf which overrides my.cnf.

The socket file is used to connect to the local server without passing from the TCP protocol, but you can force it by changing the host to the local IP address:

$pdo = new PDO("mysql:dbname=database;host=127.0.0.1", "username", "password");

Test:

<?php

    try {
        $pdo = new PDO("mysql:dbname=test;host=127.0.0.1", "user", "pwd");
        echo $pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS);
    }

    catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }

Should return: 127.0.0.1 via TCP/IP.

For an immediate solution to the above, you need to delete the MySQL socket file and restart MySQL.

To remove the socket file:

rm /var/lib/mysql/mysql.sock

To restart MySQL:

/etc/init.d/mysqld restart

If you are using shared hosting, this is something your web host will need to fix.

This usually happens when MySQL is killed or not shut down properly.

cereal that is how i connect:

try {
$dbh = new PDO('mysql:host=127.0.0.1;dbname=database', $username, $password);
$dbh->setAttribute(PDO::ERRMODE_WARNING, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
    echo "I'm sorry, I'm afraid i can't do that.";
    file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
    $dbh = null;
}

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket="MySQL"

and then this morning i tried again and i got "Unknown storage engine 'InnoDB'.

in the database phpmyadmin for all my tables under the collation tab it says "in use" and the type tab is blank. i tried:

REPAIR TABLE `table_name`

like suggested in stackoverflow because same problem as me now but that did not work

ah well, apparently the hosting providers are in a bit of a jam. They were trying to do an update and it backfired on them. -.-' haih.

It happens! Just for the log, the value for pdo_mysql.default_socket must be a valid path to the socket file as in these examples:

So this pdo_mysql.default_socket="MySQL" is not correct. The path, by the way, can be defined even in the connection string:

$dbh = new PDO("mysql:dbname=testdb;unix_socket=/path/to/mysqld.sock", "user", "pwd");

Which can be useful when using multiple instances of MySQL in the same box. Bye!

Setting up and Configuring your Microsoft SQL Server 2008 Local Database

Download SQL Server
Download SQL Server Express. Express is the Free edition of MS SQL Server

http://www.microsoft.com/en-us/download/details.aspx?id=1695

Install your SQL Server Instance

Click the Start button -> Click Microsoft SQL Server 2008 -> Click Configuration Tools -> Select SQL Server Installation Center
Select Installation -> Select New SQL Server stand-alone installation

SQL Server Installation Center Image
Select SQL Server stand-alone installation

Get your Local SQL Server Service Up and Running

Open up the SQL Server Configuration Manager

Click the Start button -> Click Microsoft SQL Server 2008 -> Click Configuration Tools -> Select SQL Server Configuration Manager

SQL Server Configuration Manager Image
Setup SQL Server Config Manager

Start up the SQL Services

You want to ensure the following services are in the "Running" State and then you want to set the following services to automatic Start mode.

SQL Server:  SQLEXPRESS 
SQL Server Browser

Right click each service -> Select Properties -> Select Service Tab

SQL Server Config Manager Console
Start up required SQL Server Services

Setup Authentication to your Local SQL Server

Click the Start button -> Click Microsoft SQL Server 2008 -> Select SQL Server Management Studio 
Click "Connect to Object Explorer" and select Server Name:

[YOUR_PC_NAME]\SQLEXPRESS

How to install MySQL database to a server machine and how to configure it, please help.

better to host on a vps as you could control everything and not rely on your host

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.