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

Purpose of the article

Since I am a beginner, I would appreciate it if you could point out any mistakes. It is posted for the purpose of memorandum and output.

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

As a beginner, I suffered from this error many times.

Besides this error, I also suffered from errors such as Can't connect to local MySQL server through socket'/tmp/mysql.sock' (38) and ERROR! The server quit without updating PID file. Looking at the article, it was mentioned that (1) creation of PID file, (2) change of authority, and (3) reinstallation support were mentioned as countermeasures, but even if I tried various articles, it was useless. (Because I am a beginner, I think it is because I do not understand the article and the cause.) I would like to leave my solution as a reference for beginners who are similarly troubled. (Since the cause has not been understood yet, no explanation is given.) So, if you try it, please do so at your own risk.

approach

In my case, I have mysql8.0 installed and it seems to cause inconvenience. So it will be uninstalled.

brew uninstall mysql

Type this command.

sudo rm -rf /usr/local/Cellar/mysql*
sudo rm -rf /usr/local/bin/mysql*
sudo rm -rf /usr/local/var/mysql*
sudo rm -rf /usr/local/etc/my.cnf
sudo rm -rf /usr/local/share/mysql*
sudo rm -rf /usr/local/opt/mysql*
sudo rm -rf /etc/my.cnf

Then install [email protected].

brew install [email protected]

After that, it will pass through the path, so export it as follows.

export PATH="/usr/local/opt/apr-util/bin:$PATH" >> ~/.bash_profile
export PATH="/usr/local/opt/[email protected]/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile

Then type mysql.server start.

mysql.server start

Will it be Starting MySQL .. SUCCESS !? I get this error every time I restart my computer, but in my case the above remedy can fix the error.

Recommended Posts

Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error remedy
Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error
ERROR 2002 (HY000) when starting MySQL: Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2)
Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (2) until resolution.
docker + mysql can't connect / Can't connect to local MySQL server through socket'var / run / mysqld / mysqld.sock' (2)
[Java] Connect to MySQL
[Java] [SQL Server] Connect to local SQL Server 2017 using JDBC for SQL Server
To connect from Spring to MySQL on virtual server (unsolved)
Connect to MySQL 8 with Java
[Android] Connect to MySQL (unfinished)
Connect to Rails server with iPhone
Connect from Java to MySQL using Eclipse
Solution that gives an error when trying to connect to DB (MySQL) in Java