Skip to Main Content

MySQL Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ERROR 2002 (HY000): Cant't connect to local MySQL server through socket '/tmp/mysql.sock'

3363898Mar 31 2018 — edited Apr 3 2018

HI,

I am currently trying to resolve a error message i get whenever i try to run the MySQL command on the shell.

I have installed the mysql 5.5 binaries on my  CentOS 7 vm in the directory "/var/lib/mysqlbuild". My main goal was to have 3 instances(mysqla, mysqlb, mysqlc) of MySQL running on the same VM.

Each Instance has his own directory /var/lib/mysqla, /var/lib/mysqlb, /var/lib/mysqlc.

I fist created 4 users by using the following command:

shell> sudo useradd mysql

shell> sudo useradd mysqla --groups mysql

....

In each directory, i have created a my.cnf file using the my-large.cnf template contained in the support-files folder  with the basic instructions:

[mysql]

socket     =     /var/lib/mysqla/tmp/mysqla.sock

port         =     33061

user        =     mysqla

datadir    =     /var/lib/mysqla/data

pid-file    =     /var/lib/mysqla/data/mysqla.pid2

log-error =     /var/lib/mysqla/log/

tmpdir    =     /var/lib//tmp

basedir  =     /var/lib/mysqlbuild

etc.....

I changed the permission for each directory by using the following command:

shell> pwd

/var/lib
shell>  chown -R mysqla:mysql mysqla

I successfully generated the mysql files in the datadir by running the following command

shell> mysql_install_db --defaults-file=/var/lib/mysqla/my.cnf

Executed the mysqld_safe cmd:

shell> mysqld_safe --defaults-file=/var/lib/mysqla/my.cnf --user=mysqla &

(confirmed with ps -ef | grep mysqld that the 2 process were running )

I changed the root pwd:

shell> /var/lib/mysqlbuild/bin/mysqladmin -u root password '<new-password>' --socket=/var/lib/mysqla/tmp/mysqla.sock

And finally i was able to access the MySQL command by using:

shell> PATH=$PATH:/var/lib/mysqlbuild/bin

shell> mysql --defaults-file=/var/lib/mysqla/my.cnf --socket=/var/lib/mysqla/tmp/mysqla.sock --port=33061 -u root -p

My question1: why do i still need to insert "--socket=/var/lib/mysqla/tmp/mysqla.sock --port=33061" when they are already in the default file "/var/lib/mysqla/my.cnf"?

If i don't put "--socket=/var/lib/mysqla/tmp/mysqla.sock" i get the following error:

shell> mysql --defaults-file=/var/lib/mysqla/my.cnf -u root -p

ERROR 2002 (HY000): Cant't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

My question2: without "PATH=$PATH:/var/lib/mysqlbuild/bin" i need to enter "/var/lib/mysqlbuild/bin" every time i need to use mysql or mysqladmin commands. Is there a way to have that value fixed by default?

This post has been answered by Dave Stokes-MySQL Community Team-Oracle on Apr 2 2018
Jump to Answer
Comments
Post Details
Added on Mar 31 2018
1 comment
390 views