Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect to local MySQL server through socket

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I tried everything I found on internet, but cannot solve the problem on Ubuntu 11.04.

I tried these things:

  • started mysqld manually using sudo /usr/sbin/mysqld start
  • started mysqld using service mysqld start
  • Checked it is running using ps ax | grep mysqld and got result 3419 pts/0 S+ 0:00 grep --color=auto mysqld
  • created the file manually at/var/run/mysqld/mysqld.sock
  • Gave rights to mysql user
  • Tried to remove and re-install but it still do not work
  • Tried tasksel to configure LAMP, every thing else works but mysql generate same error.

When run with mysqld -P 3305 it generates the error

110630  0:24:24 [Warning] Can't create test file /var/lib/mysql/nazar-studio.lower-test
110630  0:24:24 [Warning] Can't create test file /var/lib/mysql/nazar-studio.lower-test
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13)
110630  0:24:24 [ERROR] Aborting

110630  0:24:24 [Note] mysqld: Shutdown complete

Here is the mysql error log

10630  0:07:22 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:22  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:22  InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
110630  0:07:22  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
110630  0:07:22  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
110630  0:07:22  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
110630  0:07:23  InnoDB: Started; log sequence number 0 0
110630  0:07:23  InnoDB: Starting shutdown...
110630  0:07:28  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:28 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:28  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:28  InnoDB: Completed initialization of buffer pool
110630  0:07:28  InnoDB: Started; log sequence number 0 44233
ERROR: 1064  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE user ADD column Show_view_priv enum('N','Y') CHARACTER SET utf8 NOT ' at line 1
110630  0:07:28 [ERROR] Aborting

110630  0:07:28  InnoDB: Starting shutdown...
110630  0:07:34  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:34 [Note] /usr/sbin/mysqld: Shutdown complete

110630  0:07:34 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:34  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:34  InnoDB: Completed initialization of buffer pool
110630  0:07:34  InnoDB: Started; log sequence number 0 44233
110630  0:07:34  InnoDB: Starting shutdown...
110630  0:07:39  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:39 [Note] Plugin 'FEDERATED' is disabled.
110630  0:07:39  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:07:39  InnoDB: Completed initialization of buffer pool
110630  0:07:39  InnoDB: Started; log sequence number 0 44233
ERROR: 1050  Table 'plugin' already exists
110630  0:07:39 [ERROR] Aborting

110630  0:07:39  InnoDB: Starting shutdown...
110630  0:07:44  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:07:44 [Note] /usr/sbin/mysqld: Shutdown complete

110630  0:18:30 [Note] Plugin 'FEDERATED' is disabled.
110630  0:18:30  InnoDB: Initializing buffer pool, size = 8.0M
110630  0:18:30  InnoDB: Completed initialization of buffer pool
110630  0:18:30  InnoDB: Started; log sequence number 0 44233
mysqld: Too many arguments (first extra is 'start').
Use --verbose --help to get a list of available options
110630  0:18:30 [ERROR] Aborting

110630  0:18:30  InnoDB: Starting shutdown...
110630  0:18:35  InnoDB: Shutdown completed; log sequence number 0 44233
110630  0:18:35 [Note] mysqld: Shutdown complete

How can this error be resolved?

like image 499
Nazar Hussain Avatar asked Jun 29 '11 19:06

Nazar Hussain


People also ask

Can connect to local MySQL server through socket?

It means either the MySQL server is not installed/running, or the file mysql. sock doesn't exist in /var/lib/mysql/ . There are a couple of solutions for this error.

How do I connect to a local MySQL server?

Step 3: Connect to a Local MySQL Server Enter mysql.exe -uroot -p , and MySQL will launch using the root user. MySQL will prompt you for your password. Enter the password from the user account you specified with the –u tag, and you'll connect to the MySQL server.

Can't connect to local MySQL server through socket '/?

Another possible solution to the >can't connect to local mysql server through socket> error message is to try and connect to the MySQL using the 127.0. 0.1 ip address instead of localhost. When you use localhost to connect to MySQL, the operating system uses the socket connector.


4 Answers

I did experiments and finally solve it with these commands

sudo chown mysql:root /var/lib/mysql/ -R
sudo chmod g+rw /var/lib/mysql/ -R
sudo /usr/sbin/mysqld --skip-grant &

It get running...... Hurraaahhhhhhhhhh!!!!!!!!!!!!

like image 100
Nazar Hussain Avatar answered Oct 02 '22 18:10

Nazar Hussain


Your log actually tells you the issue:

mysqld: Too many arguments (first extra is 'start').

Just start the daemon without the word 'start'. Instead of:

sudo /usr/sbin/mysqld start

it should be just:

sudo /usr/sbin/mysqld

like image 35
user932973 Avatar answered Oct 02 '22 20:10

user932973


It looks like either it can't create a file in /var/lib/mysql/. If you look at the errode 13, it is generally means permission errors.

1) Make sure that mySQL can write to the directory /var/lib/mysql and/or that mySQL owns that directory. Do a:

cd /var/lib ; ls -la | grep mysql

To be sure.

2) If you are trying to start with the mySQL user, start it with root instead (You probably are, but it's worth checking).

3) If you are running something like SElinux, make sure that you enable it for mySQL access. I doubt that is the case, but it's worth checking.

4) Small note: Don't create the sock file - mysql will create one once it is up and running properly. If it still in the run directory, delete it.

like image 31
Rilindo Avatar answered Oct 02 '22 18:10

Rilindo


If you have multiple mysql servers installed then make sure you run the correct MYSQL or change your path settings. For example:

/opt/lampp/bin/mysql -u root -p 

I have XAMPP installed , the solution worked for me.

like image 35
Kamal Asawara Avatar answered Oct 02 '22 20:10

Kamal Asawara