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

Correct installation steps:

1. Execute:

$ brew install mysql

/usr/local/etc/ 2.  Create or modify my.cnf under, example:

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8

[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
init-connect ='SET NAMES utf8'
max_allowed_packet = 64M
bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock
innodb_file_per_table=1

[mysqld_safe]
timezone = '+0:00'

3. Like after installing mysql, he will prompt you to init database, and provide the following two sentences for you to execute, it is likely that you did not execute these two sentences

$ unset TMPDIR
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

4. Then you can point  mysql.server start to start. For security, you can also execute the security setup wizard and configure it step by step according to the prompts

$ mysql_secure_installation

I had previously encountered a similar problem and edited the content, but I forgot the source.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325357883&siteId=291194637