programing tip

소켓 홈브류를 통해 로컬 MySQL 서버에 연결할 수 없습니다.

itbloger 2020. 8. 28. 07:06
반응형

소켓 홈브류를 통해 로컬 MySQL 서버에 연결할 수 없습니다.


최근에 homebrew ( brew install mysql)를 사용 하여 MySQL을 설치하려고 시도했는데 실행하려고하면 다음 오류가 발생합니다.

오류 2002 (HY000) : '/tmp/mysql.sock'소켓을 통해 로컬 MySQL 서버에 연결할 수 없습니다 (2).

더 없다 /tmp/mysql.sock도 아니다 /var/lib/mysql.sock.

검색했지만 mysql.sock파일을 찾지 못했습니다 .

이 문제를 어떻게 해결할 수 있습니까?


다음을 통해 서버를 실행했을 때

mysql.server start

/tmp/mysql.sock에 소켓이 표시되어야합니다 . 그러나 시스템은 /var/mysql/mysql.sock 에서 예상하는 것 같습니다 . 이 문제를 해결하려면 / var / mysql에 심볼릭 링크를 생성해야합니다 .

sudo mkdir /var/mysql

sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

이것은 나를 위해 그것을 해결했습니다. 이제 내 phpMyAdmin이 localhost 127.0.0.1 과 함께 행복하게 작동 합니다 .

신용은 헨리 에게 간다


mysql 서버가 시작되지 않은 것 같습니다. 일반적으로 중지 명령을 실행 한 다음 다시 시작합니다.

mysqld stop
mysql.server start

같은 오류이며 이것은 나를 위해 작동합니다.


"localhost"대신 "127.0.0.1"을 사용하여 연결해보십시오.


다른 mysql (8.0) 설치에서 제거되지 않은 일부 디렉토리가 남아 있습니다.

다음을 수행하여이 문제를 해결했습니다.

먼저 mysql 제거

brew uninstall mysql@5.6

제거되지 않은 폴더 / 파일 삭제

rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf

mysql을 다시 설치하고 연결하십시오.

brew install mysql@5.6
brew link --force mysql@5.6

서비스 활성화 및 시작

brew services start mysql@5.6

1) 아래 명령을 실행할 때 "mysql 중지됨"이 표시되는 경우;

brew services list

2) 아래 명령으로 mysql을 시작할 수 있다면;

mysql server start

이것은 의미합니다; mysql은 수동으로 시작할 수 있지만 운영 체제가 시작될 때 자동으로 시작되지 않습니다. 서비스에 mysql을 추가하면이 문제가 해결됩니다. 이를 위해 아래 명령을 실행할 수 있습니다.

brew services start mysql

그런 다음 운영 체제를 다시 시작하고 mysql에 연결하여 자동으로 시작되는지 확인할 수 있습니다. 나는 똑같이했고 아래 오류 수신을 중단했습니다.

오류 2002 (HY000) : '/tmp/mysql.sock'소켓을 통해 로컬 MySQL 서버에 연결할 수 없습니다 (2).

이게 도움이 되길 바란다.


파일 /tmp/mysql.sock은 임시 폴더에 있기 때문에 아마도 Named-Pipe 일 것입니다. 명명 된 파이프는 영구적으로 저장되지 않는 특수 파일입니다.

두 개의 프로그램을 만들고 한 프로그램이 다른 프로그램에 메시지를 보내도록하려면 텍스트 파일을 만들 수 있습니다. 한 프로그램은 텍스트 파일에 무언가를 쓰고 다른 프로그램은 다른 프로그램이 쓴 것을 읽습니다. 이것이 바로 파이프입니다. 단, 컴퓨터 하드 디스크에 파일을 쓰지 않고 IE는 파일을 영구적으로 저장하지 않습니다 (파일을 만들고 저장할 때처럼).

소켓은 파이프와 똑같습니다. 차이점은 소켓은 일반적으로 네트워크를 통해 컴퓨터간에 사용된다는 것입니다. 소켓은 정보를 다른 컴퓨터로 보내거나 다른 컴퓨터에서 정보를받습니다. 파이프와 소켓은 모두 임시 파일을 사용하여 '통신'할 수 있도록 공유합니다.

이 경우 MySql이 어떤 것을 사용하고 있는지 식별하기가 어렵습니다. 그래도 중요하지 않습니다.

명령 mysql.server start은 해당 특수 파일을 생성하고 변경을 기다릴 ( listen쓰기를 위해) 무한 루프를 실행하는 '서버'(프로그램) 를 가져와야합니다.

그 후, 일반적인 문제는 MySql 프로그램에 컴퓨터에 파일을 생성 할 권한이 없기 때문에 루트 권한을 부여해야 할 수 있습니다.

sudo mysql.server start

macos mojave를 설치 한 후 mysql 폴더를 지우고 그렇지 않으면 권한 관련 사항을 /usr/local/var/mysql통해 다시 설치 brew install mysql해야했습니다.


동일한 오류가 발생했으며 이것이 도움이되었습니다.

$ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
$launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$mysql -uroot
mysql>

이 문제를 해결하기 위해 많은 시간을 보냈고이 오류를 찾을 때 항상이 페이지로 돌아 왔기 때문에 누군가가 내가 잃어버린 시간을 절약하기를 바라면서 여기에 솔루션을 남겨 둘 것입니다. 제 경우에는 MySql이 아닌 mariadb를 사용하고 있지만이 솔루션을 필요에 맞게 조정할 수 있습니다.

내 문제

동일하지만 내 설정이 약간 다릅니다 (mysql 대신 mariadb).

homebrew와 함께 mariadb 설치

$ brew install mariadb

데몬 시작

$ brew services start mariadb

연결을 시도했지만 위에서 언급 한 오류가 발생했습니다.

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

내 솔루션

find out which my.cnf files are used by mysql (as suggested in this comment):

$ mysql --verbose --help | grep my.cnf
/usr/local/etc/my.cnf ~/.my.cnf
                        order of preference, my.cnf, $MYSQL_TCP_PORT,

check where the Unix socket file is running (almost as described here):

$ netstat -ln | grep mariadb
.... /usr/local/mariadb/data/mariadb.sock

(you might want to grep mysql instead of mariadb)

Add the socket file you found to ~/.my.cnf (create the file if necessary)(assuming ~/.my.cnf was listed when running the mysql --verbose ...-command from above):

[client]
socket = /usr/local/mariadb/data/mariadb.sock

Restart your mariadb:

$ brew services restart mariadb

After this I could run mysql and got:

$ mysql -uroot
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

So I run the command with superuser privileges instead and after entering my password I got:

$ sudo mysql -uroot
MariaDB [(none)]>

Notes:

  1. I'm not quite sure about the groups where you have to add the socket, first I had it [client-server] but then I figured [client] should be enough. So I changed it and it still works.

  2. When running mariadb_config | grep socket I get: --socket [/tmp/mysql.sock] which is a bit confusing since it seems that /usr/local/mariadb/data/mariadb.sock is the actual place (at least on my machine)

  3. I wonder where I can configure the /usr/local/mariadb/data/mariadb.sock to actually be /tmp/mysql.sockso I can use the default settings instead of having to edit my .my.cnf (but I'm too tired now to figure that out...)

  4. At some point I also did things mentioned in other answers before coming up with this.


I faced the same problem on my mac and solved it, by following the following tutorials

https://mariadb.com/resources/blog/installing-mariadb-10116-mac-os-x-homebrew

But don't forget to kill or uninstall the old version before continuing.

Commands:

brew uninstall mariadb

xcode-select --install

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - See more at: https://mariadb.com/resources/blog/installing-mariadb-10116-mac-os-x-homebrew#sthash.XQoxRoJp.dpuf

brew doctor

brew update

brew info mariadb

brew install mariadb

mysql_install_db

mysql.server start

Just to add to these answers, In my case I had no local mySQL server, it was running inside a docker container. So the socket file does not exist and will not be accessible for the "mysql" client.

The sock file gets created by mysqld and mysql uses this to communicate with it. However if your mySql server is not running local, it does not require the sock file.

By specifying a host name/ip the sock file is not required e.g.

mysql --host=127.0.0.1 --port=3306 --user=xyz --password=xyz

You'll need to run mysql_install_db - easiest way is if you're in the install directory:

$ cd /usr/local/Cellar/mysql/<version>/ 
$ mysql_install_db

Alternatively, you can feed mysql_install_db a basedir parameter like the following:

$ mysql_install_db --basedir="$(brew --prefix mysql)"

just to complete this thread. therefore MAMP (PRO) is used pretty often

the path here is

/Applications/MAMP/tmp/mysql/mysql.sock

I manually started mysql in the system preferences pane by initialising the database and then starting it. This solved my problem.


After a restart I could not connect with the local mariadb, a search also brought me to this page and I wanted to share my solution with you.

I noticed that the directory my.cnf.d in /usr/local/etc/ is missing.

This is a known bug with homebrew that is described and solved there. https://github.com/Homebrew/homebrew-core/issues/36801

fast way to fix: mkdir /usr/local/etc/my.cnf.d


When running mysql_secure_installation and entering the new password I got:


Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


I noticed when trying the following from this answer:

netstat -ln | grep mysql

It didn't return anything, and I took that to mean that there wasn't a .sock file.

So, I added the following to my my.cnf file (either in /etc/my.cnf or in my case, /usr/local/etc/my.cnf).

Under:

[mysqld]
socket=/tmp/mysql.sock

Under:

[client]
socket=/tmp/mysql.sock

This was based on this post.

Then stop/start mysql again and retried mysql_secure_installation which finally let me enter my new root password and continue with other setup preferences.

I hope this helps someone. Man, I hate this stuff...


In my case, the culprit was found in the logfiles:

$ tail /usr/local/var/mysql/<hostname>.lan.err
2019-09-19  7:32:21 0 [ERROR] InnoDB: redo log file './ib_logfile0' exists. Creating system tablespace with existing redo log files is not recommended. Please delete all redo log files before creating new system tablespace.
2019-09-19  7:32:21 0 [ERROR] InnoDB: Database creation was aborted with error Generic error. You may need to delete the ibdata1 file before trying to start up again.

So I renamed ib_logfile0 to get rid of the error (I had to do the same with ib_logfile1 afterwards).

mv /usr/local/var/mysql/ib_logfile0 /usr/local/var/mysql/ib_logfile0_bak
mv /usr/local/var/mysql/ib_logfile1 /usr/local/var/mysql/ib_logfile1_bak
brew services restart mariadb

rm -rf /usr/local/var/mysql/ib_logfile*

참고URL : https://stackoverflow.com/questions/15016376/cant-connect-to-local-mysql-server-through-socket-homebrew

반응형