Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
Explorer

After install mysql as per this cloudera guide , which includes changing the "/etc/mysql/my.cnf" to the one they recommend.

 

Now when I try :

sudo mysql -u root -p

I get 

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

I need to do it as follows to be able to connect to mysql:

mysql -u root -p -h 127.0.0.1

by the way I have tried the following to solve it but with no luck .... same error

sudo mkdir -p /var/run/mysqld/

sudo touch /var/run/mysqld/mysqld.pid

sudo touch /var/run/mysqld/mysqld.sock

sudo chown mysql:mysql -R /var/run/mysqld

sudo service mysql restart
1 ACCEPTED SOLUTION

avatar
Explorer

I have changed this line in my.cnf:

socket=/var/lib/mysql/mysql.sock

to this 

socket=/var/run/mysqld/mysql.sock

and that fixed it!

 

I think Cloudera has to review its installation guide ... I have faced many difficulties so far ...
They tell you to do A and B to get C  ... you do A and B but you don't get C!! ... 

 

View solution in original post

3 REPLIES 3

avatar
Super Collaborator

Check bind-address in my.cnf config file, is it set to 127.0.0.1?

avatar
Explorer
First I would like to note that with the default my.cnf that comes with the fresh installation of MySQL the login works fine.

Now to answer your question, this is what I have pasted in “my.cnf” as recommended by Cloudera guide, and I cannot see any bind-address option:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
transaction-isolation = READ-COMMITTED
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
symbolic-links = 0

key_buffer_size = 32M
max_allowed_packet = 32M
thread_stack = 256K
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1

max_connections = 550
#expire_logs_days = 10
#max_binlog_size = 100M

#log_bin should be on a disk with enough free space.
#Replace '/var/lib/mysql/mysql_binary_log' with an appropriate path for your
#system and chown the specified folder to the mysql user.
log_bin=/var/lib/mysql/mysql_binary_log

#In later versions of MySQL, if you enable the binary log and do not set
#a server_id, MySQL will not start. The server_id must be unique within
#the replicating group.
server_id=1

binlog_format = mixed

read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M

# InnoDB settings
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

sql_mode=STRICT_ALL_TABLES

avatar
Explorer

I have changed this line in my.cnf:

socket=/var/lib/mysql/mysql.sock

to this 

socket=/var/run/mysqld/mysql.sock

and that fixed it!

 

I think Cloudera has to review its installation guide ... I have faced many difficulties so far ...
They tell you to do A and B to get C  ... you do A and B but you don't get C!! ...