mysql5在mac os x下的安装,可以直接下载dmg安装包安装,也可通过prot安装,,过程比较容易。
在安装完成后,却发现出错:运行 mysql5 -u root,提示:
mysql5 -u root –p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)
后来下了个mysql的管理工具:Mysql WorkBench,通过右下角的创建数据库实例,发现可以连接到数据库上。。如下图
在参考了http://www.iteye.com/problems/49993 之后,在连接数据库时加上主机就可以访问ok啦:
mysql5 -u root -h 127.0.0.1
xxx$ mysql5 -u root -h 127.0.0.1
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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> quit
Bye
在连接成功后:
mysql> show variables like 'socket';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| socket | /tmp/mysql.sock |
+---------------+-----------------+
1 row in set (0.03 sec)
发现sock的路径,于是做一个软连接即可:
$ sudo ln /tmp/mysql.sock /opt/local/var/run/mysql5/mysqld.sock
随后在终端输入mysql5即可进入mysql控制台。
参考:http://www.iteye.com/problems/49993