1. 程式人生 > >osx下brew install mysql之後mysql報錯的問題

osx下brew install mysql之後mysql報錯的問題

報錯如下:

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


然後檢視/tmp/目錄下根本沒有mysql.sock

其實當年安裝完brew install mysql之後,還要這樣:

brew info mysql來進行配置

用他們推薦的mysql.server start無法啟動,報錯:

junjiedeMacBook-Pro:mysql junjielin$ mysql.server start

Starting MySQL

..................................................................................................... ERROR! The server quit without updating PID file (/usr/local/var/mysql/junjiedeMacBook-Pro.local.pid).


但是突然發現用這種方式可以:

junjiedeMacBook-Pro:mysql junjielin$ mysql -uroot -h127.0.0.1 -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.19 Homebrew

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 


這是怎麼回事?

後來重啟電腦之後正常了!

Last login: Fri Jun 13 18:36:35 on console

junjiedeMacBook-Pro:~ junjielin$ ps -ef|grep mysql

  501   349   343   0  6:40下午 ttys000    0:00.00 grep mysql

junjiedeMacBook-Pro:~ junjielin$ mysqlmysql -uroot -h127.0.0.1 -p

-bash: mysqlmysql: command not found

junjiedeMacBook-Pro:~ junjielin$ mysql -uroot -h127.0.0.1 -p

Enter password: 

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)

junjiedeMacBook-Pro:~ junjielin$ mysql.server start

Starting MySQL

. SUCCESS! 

junjiedeMacBook-Pro:~ junjielin$ ps -ef|grep mysql

  501   363     1   0  6:41下午 ttys000    0:00.02 /bin/sh /usr/local/Cellar/mysql/5.6.19/bin/mysqld_safe --datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/junjiedeMacBook-Pro.local.pid

  501   459   363   0  6:41下午 ttys000    0:00.41 /usr/local/Cellar/mysql/5.6.19/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.6.19 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.6.19/lib/plugin --log-error=/usr/local/var/mysql/junjiedeMacBook-Pro.local.err --pid-file=/usr/local/var/mysql/junjiedeMacBook-Pro.local.pid

  501   461   343   0  6:41下午 ttys000    0:00.00 grep mysql

junjiedeMacBook-Pro:~ junjielin$ mysql 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.19 Homebrew

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| test               |

+--------------------+

2 rows in set (0.00 sec)

mysql> exit

Bye

junjiedeMacBook-Pro:~ junjielin$ clear


現在mysql沒有問題了~~

2016.2.24:

今天有碰到這個問題了,我刪除了/usr/local/var/mysql/*.err 的檔案,一切就沒問題了: ), mysql.server start 成功啟動mysql資料庫。