MySQL won’t start or won’t installed

MySQLmysql5

I'm trying to get a local LAMP setup on my Ubuntu desktop. I'm successfully got PHP install but I'm having trouble with MySQL

If PHP tries to connet to MySQL I get this error:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /var/www/testing.php on line 3
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

If I try via command line I get much the same error:
owen@desktop:~$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)

Weirdly "/var/run/mysqld" does not exist.

Running a whereis command I get the following:
owen@desktop:~$ whereis mysqld.sock
mysqld: /usr/sbin/mysqld /usr/share/man/man8/mysqld.8.gz

So is MySQL even installed? Well acording to dpkg
owen@desktop:~$ dpkg -l | grep mysql
ii libapache2-mod-auth-mysql 4.3.9-13ubuntu1 Apache 2 module for MySQL authentication
ii libdbd-mysql-perl 4.016-1 Perl5 database interface to the MySQL database
ii libmysqlclient15off 5.1.30really5.0.83-0ubuntu3 MySQL database client library
ii libmysqlclient16 5.1.49-1ubuntu8.1 MySQL database client library
ii mysql-admin 5.0r14+openSUSE-2.1 GUI tool for intuitive MySQL administration
ii mysql-client-5.1 5.1.49-1ubuntu8.1 MySQL database client binaries
ii mysql-client-core-5.1 5.1.49-1ubuntu8.1 MySQL database core client binaries
ii mysql-common 5.1.49-1ubuntu8.1 MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-gui-tools-common 5.0r14+openSUSE-2.1 Architecture independent files for MySQL GUI Tools
ii mysql-query-browser 5.0r14+openSUSE-2.1 Official GUI tool to query MySQL database
ii mysql-server 5.1.49-1ubuntu8.1 MySQL database server (metapackage depending on the latest version)
ii mysql-server-5.1 5.1.49-1ubuntu8.1 MySQL database server binaries and system database setup
ii mysql-server-core-5.0 5.1.30really5.0.83-0ubuntu3 MySQL database core server files
ii mysql-server-core-5.1 5.1.49-1ubuntu8.1 MySQL database server binaries
ii php5-mysql

Can someone please help I'm really confused as what to do next. I'm not a Linux expert at all most of these commands I've ran I found of diffrent blogs and help forums.

Best Answer

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Sounds like you're doing something like.....

mysql_connect('localhost'....

The mysql client lib, when it sees 'localhost' doesn't bother making a network conection - it uses the local file (unix) socket. In order to find this socket, it should check the php.ini setting, or use the value in my.cnf, or failing these, compiled in default(s).

Check the mysql is running

ps auxwww | grep mysqld

Check its listening on a network socket:

netstats -nap

The above should also show what file socket it is listening on.

Assuming this is a default installation (i.e. listening on the network port and with no root password) You should be able to connect to the network socket using

mysql -u root -h 127.0.0.1

Then show variables like '%sock%'

will also show you where the filesystem socket is.

Update your php.ini setting, e.g.

mysql.default_socket = /var/lib/mysql/mysql.sock

and restart your webserver.

Related Topic