본문 바로가기
DB/MariaDB

mac mariaDB 설치 error - Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock

by D.B_18 2022. 2. 1.

mac에 mariaDB를 설치하던 중 다음과 같은 오류가 발생했습니다.

Can't connect to local MySQL server through socket

1. mariaDB 완전 삭제

brew services stop mariadb
brew unlink mariadb
brew remove mariadb
brew uninstall mariadb
brew cleanup

 

homebrew로 mariaDB를 설치했다면, 터미널에서 위의 명령어를 입력해 mariaDB를 삭제하고 아래 경로의 폴더를 찾아 제거합니다.

/opt/homebrew/var/mysql

2. mariaDB 재설치

brew install mariadb

 

mariaDB가 설치되었다면 다음의 명령어를 통해 서비스를 실행/중지 할 수 있습니다.

brew services start mariadb
brew services stop mariadb

 

mariaDB를 동작시켰다면 명령어를 통해 상태를 확인할 수 있습니다.

brew services list

 

다음으로 관리자 계정인 root 계정을 설정해줍니다.

sudo mariadb-secure-installation

 

sudo 비밀번호를 입력한 후에 초기 root 계정의 비밀번호를 요구하는 화면이 나오면 Enter로 넘어갑니다.

그리고 나서 아래와 같이 설정해줍니다.

OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y

Dropping test database...
... Success!
Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

위의 설정을 마치고 나서는 설정해준 비밀번호로 mariaDB를 사용할 수 있습니다.

mysql -u root -p
728x90
반응형