Watheq's avatar
Level 14

Problem with SQLSTATE[HY000] [2002] every time I launch my computer

Every time I launch my computer when I type php artisan serve I get these commands..

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `sessions` where `id` = KsL5wVKGbNVEpBvHCDrEr8Q8eoZWA3ja2KGejyvZ limit 1)

I know the solution to my problem which is typing the problem:

  1. sudo chown -R _mysql:mysql /usr/local/var/mysql
  2. sudo mysql.server start

I want it to persist. I don't want this problem to show agoin

By the way, I am using:

  • Mac, big Sure
  • Mysql using brew
  • Laravel 8
0 likes
9 replies
Watheq's avatar
Level 14

@Nakov I don't find MySQL in system preferences. I have installed it using brew.

Nakov's avatar

@Watheq you should follow the complete post my friend, there is a manual approach through the terminal:

$> cd /Library/LaunchDaemons
$> sudo launchctl load -F com.oracle.oss.mysql.mysqld.plist

anyhow, starting the MySQL deamon is what you should be looking for.

1 like
Watheq's avatar
Level 14

@Nakov I follow the instruciton but there is No such file or directory

Nakov's avatar

@Watheq When installing MySQL using brew, it provides details at the end of the install on how to launch the service and the deamon. As I said above, launching the MySQL as a deamon is what you should be looking for.

Try this approach: https://stackoverflow.com/a/6378429/1457270 ignore the first part where he removes the installation and check which step you are missing from the "Start from scratch part".

1 like
johnDoe220's avatar

install xampp

https://www.apachefriends.org/download.html
esorone's avatar

I think one of these should work for you:

To have launchd start mysql at login:

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

Then to load mysql now:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Or, if you don't want/need launchctl, you can just run:

mysql.server start

Kr

Watheq's avatar
Watheq
OP
Best Answer
Level 14

After searching in multiuple places I found the solution:

  • reset brew permission
  • then type this command: sudo brew services start mysql

that's it.

Please or to participate in this conversation.