通过brew install mysql
安装mysql后
#第一步:打开mysql服务
mysql.server start
#第二步:执行mysql_secure_installation,根据提示设置密码
mysql_secure_installation
下一步尝试连接mysql
➜ ~ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.16 Homebrew
Copyright (c) 2000, 2016, 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 |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
最后,当用PHP连接mysql的时候会出现一个关于mysql.sock的错误。
SQLSTATE[HY000] [2002] No such file or directory
查了一下,Mysql的连接有两种,一种是通过TCP/TP,而另一种正是socket。
#通过此命令查找mysql.sock。此文件在mysql服务启动时会生成
sudo find / -name mysql.sock
#结果
/private/tmp/mysql.sock
而系统默认貌似会去/var/mysql/mysql.sock
下去找,创建一个软链(若没有mysql文件,先创建),解决此问题。
sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock
网友评论