0

I am not able to run mysql. I get the error when I try to run mysql -u root -p

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

And when I try to sudo mysql.server start I got another error.

ERROR! The server quit without updating PID file (/opt/homebrew/var/mysql/RFL723.local.pid).

I tried completely removing and reinstalling mysql@8.0.33 and mysql@5.7 many time.

attaching some log

2023-07-26T19:33:30.6NZ mysqld_safe Logging to '/opt/homebrew/var/mysql/RFL723.local.err'.
2023-07-26T19:33:30.6NZ mysqld_safe Starting mysqld daemon with databases from /opt/homebrew/var/mysql
2023-07-26T19:33:30.321526Z 0 [System] [MY-010116] [Server] /opt/homebrew/opt/mysql/bin/mysqld (mysqld 8.0.33) starting as process 61538
2023-07-26T19:33:30.322613Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /opt/homebrew/var/mysql/ is case insensitive
2023-07-26T19:33:30.322621Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2023-07-26T19:33:30.322658Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-07-26T19:33:30.322729Z 0 [System] [MY-010910] [Server] /opt/homebrew/opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.33)  Homebrew.
2023-07-26T19:33:30.6NZ mysqld_safe mysqld from pid file /opt/homebrew/var/mysql/RFL723.local.pid ended
2023-07-26T19:33:40.6NZ mysqld_safe Logging to '/opt/homebrew/var/mysql/RFL723.local.err'.
2023-07-26T19:33:40.6NZ mysqld_safe Starting mysqld daemon with databases from /opt/homebrew/var/mysql
2023-07-26T19:33:40.600285Z 0 [System] [MY-010116] [Server] /opt/homebrew/opt/mysql/bin/mysqld (mysqld 8.0.33) starting as process 61645
2023-07-26T19:33:40.601389Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /opt/homebrew/var/mysql/ is case insensitive
2023-07-26T19:33:40.601396Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2023-07-26T19:33:40.601435Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-07-26T19:33:40.601505Z 0 [System] [MY-010910] [Server] /opt/homebrew/opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.33)  Homebrew.
2023-07-26T19:33:40.6NZ mysqld_safe mysqld from pid file /opt/homebrew/var/mysql/RFL723.local.pid ended
2023-07-26T19:33:50.6NZ mysqld_safe Logging to '/opt/homebrew/var/mysql/RFL723.local.err'.
2023-07-26T19:33:50.6NZ mysqld_safe Starting mysqld daemon with databases from /opt/homebrew/var/mysql
2023-07-26T19:33:50.880612Z 0 [System] [MY-010116] [Server] /opt/homebrew/opt/mysql/bin/mysqld (mysqld 8.0.33) starting as process 61751
2023-07-26T19:33:50.881695Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /opt/homebrew/var/mysql/ is case insensitive
2023-07-26T19:33:50.881707Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2023-07-26T19:33:50.881740Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-07-26T19:33:50.881814Z 0 [System] [MY-010910] [Server] /opt/homebrew/opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.33)  Homebrew.
2023-07-26T19:33:50.6NZ mysqld_safe mysqld from pid file /opt/homebrew/var/mysql/RFL723.local.pid ended

Current OS: 13.5 (22G74) Mac M2

Raja Sharma
  • 460
  • 1
  • 7
  • 19
  • Check the MySQL server logs for details. – tadman Jul 26 '23 at 19:32
  • added log @tadman – Raja Sharma Jul 26 '23 at 19:36
  • Just to keep it straight, we have an M2 processor Mac running a linux shell that is running mysql? Can you connect to localhost directly and perhaps its just the socket that is derped? – easleyfixed Jul 26 '23 at 19:47
  • Yes @easleyfixed – Raja Sharma Jul 26 '23 at 19:49
  • Ok as a test can you try to connect using MySQL Workbench to connect to it ? Download here --> https://dev.mysql.com/downloads/workbench/ – easleyfixed Jul 26 '23 at 19:58
  • And also curious if this post has info that would help you ? --> https://stackoverflow.com/questions/5376427/cant-connect-to-local-mysql-server-through-socket-var-mysql-mysql-sock-38 – easleyfixed Jul 26 '23 at 20:03
  • You shouldn't be starting manually via `mysql.server` if you've installed via Homebrew. This should be managed via `brew services` which is a wrapper around `launchctl`. – tadman Jul 26 '23 at 21:20

1 Answers1

0

The error indicates you're running mysql with the wrong permissions.

How did you start your mysql instance?

A recommended way to install and manage mysql in mac is using brew

brew install mysql
brew services start mysql


mysql -u root -p

make sure that this is the correct instance you're running which mysql

The error in running it as sudo implies you're lacking permissions to create the pid file needed to run the process, due to a permission issue.

I'd try the brew repair utility brew doctor

or

sudo chown -R _mysql /opt/homebrew/var/mysql  

which should allow the mysql user to write the PID process into that directory.

Simeon Borisov
  • 417
  • 2
  • 6