Nepalon 2010-09-11 17:04
浏览 457
已采纳

在mac osx10.6下安装mysql后,启动总是报错ERROR 2002 (HY000): Can't connect to local MySQL ser

要在mac10.6下安装mysql以便rails开发,装了两天都没有成功。之前没用过mac或linux开发,一直用windows,所以希望高手们能指点一下。
我在安装时参考了以下文章:
http://beike.iteye.com/blog/617341
http://hqman.iteye.com/blog/258979
下面是我的安装过程及错误:
安装和初始化mysql
[code="java"]port search mysql
sudo port install mysql5-server
###########################################################

A startup item has been generated that will aid in

starting mysql5-server with launchd. It is disabled

by default. Execute the following command to start it,

and to cause it to launch at startup:

#

sudo port load mysql5-server

###########################################################
---> Installing mysql5-server @5.1.50_0


  • In order to setup the database, you might want to run
  • sudo -u _mysql mysql_install_db5
  • if this is a new install ****************************************************** ---> Activating mysql5-server @5.1.50_0 ---> Cleaning mysql5-server[/code]

[code="java"]sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h bogon password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script![/code]
配置mysql:
开机自动启动mysql
[code="java"]sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist [/code]
启动mysql
如果要快捷启动,则要先设置aliases,再用aliases来启动:
mate ~/.profile打开这个配置文件,输入以下内容:
[code="java"]alias mysqlstart='sudo /opt/local/bin/mysqld_safe5 &'

alias mysqlstop='/opt/local/bin/mysqladmin5 -u root -p shutdown'[/code]
启动mysql
[code="java"]mysqlstart
[1] 62478[/code]
如果没有设置aliases,则用以下命令来启动
/opt/local/share/mysql5/mysql/mysql.server start

验证mysql安装成功:
[code="java"]mysqladmin5 -u root -p ping
error: 'Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/opt/local/var/run/mysql5/mysqld.sock' exists!
[/code]

[code="java"]mysql5 -u root –p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)[/code]
mate /opt/local/etc/mysql5/my.cnf并输入以下内容(参考http://beike.iteye.com/blog/617341):
[code="java"][mysqld_safe]
socket = /tmp/mysql.sock[/code]
再调用 mysql5 -u root –p还是报相同错误。

  • 写回答

3条回答 默认 最新

  • zaqwsxedc 2010-09-14 10:40
    关注

    试一下用这个命令能否连接:
    [code="java"]
    mysql5 -u root –p -h 127.0.0.1
    [/code]

    如果能连接,使用这个命令看看socket到底是什么?
    [code="java"]
    show variables like 'socket';
    [/code]

    我是直接装的这个:http://www.mysql.com/downloads/mirror.php?id=392754
    socket是:
    [code="java"]
    mysql> show variables like 'socket';
    +---------------+-----------------+
    | Variable_name | Value |
    +---------------+-----------------+
    | socket | /tmp/mysql.sock |
    +---------------+-----------------+
    1 row in set (0.03 sec)
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页