无法通过socket'/tmp/mysql.sock'连接到本地MySQL服务器(2)

时间:2011-10-21 00:12:21

标签: mysql terminal rvm osx-lion mysql.sock

我正在尝试在终端上运行mysql客户端。我已经安装了最新的mysql gem。

 ➜  ~ git:(master) ✗ ruby -v
    ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
    ➜  ~ git:(master) ✗ rails -v
    Rails 2.3.14
    ➜  ~ git:(master) ✗ which mysql
    mysql: aliased to nocorrect mysql
    ➜  ~ git:(master) ✗ which ruby
    /usr/bin/ruby
    ➜  ~ git:(master) ✗ which rails
    /usr/bin/rails
    ➜  ~ git:(master) ✗ gem list

*** LOCAL GEMS ***

actionmailer (2.3.14)
actionpack (2.3.14)
activerecord (2.3.14)
activeresource (2.3.14)
activesupport (2.3.14)
builder (2.1.2)
bundler (1.0.21)
capistrano (2.9.0)
capybara (0.3.9)
cgi_multipart_eof_fix (2.5.0)
childprocess (0.2.2)
columnize (0.3.4, 0.3.3)
cucumber (0.9.4)
cucumber-rails (0.3.2)
culerity (0.2.15)
daemons (1.1.4)
database_cleaner (0.6.7)
diff-lcs (1.1.3)
expertiza-authlogic (2.1.6.1)
fastercsv (1.5.4)
fastthread (1.0.7)
ffi (1.0.10, 1.0.9)
gdata (1.1.2)
gem_plugin (0.2.3)
gherkin (2.2.9)
highline (1.6.2)
hoptoad_notifier (2.4.11)
json (1.4.6)
json_pure (1.6.1)
linecache (0.46)
mime-types (1.16)
mongrel (1.1.5)
mysql (2.8.1)
mysql2 (0.3.7)
net-scp (1.0.4)
net-sftp (2.0.5)
net-ssh (2.2.1)
net-ssh-gateway (1.1.0)
nokogiri (1.5.0)
rack (1.1.2)
rack-test (0.6.1)
rails (2.3.14)
rake (0.9.2)
rbx-require-relative (0.0.5)
rdoc (3.11)
RedCloth (4.2.8)
rgl (0.4.0)
ruby-debug (0.10.4)
ruby-debug-base (0.10.4)
rubyzip (0.9.4)
selenium-webdriver (2.8.0, 2.7.0)
stream (0.5)
term-ansicolor (1.0.7, 1.0.6)

➜  expertiza git:(master) ✗ sudo su
Password:
sh-3.2# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
sh-3.2# 

我无法摆脱上述错误。我在mysql.sock file中创建了/Users/HPV/expertiza/tmp/sockets。在我写的mysql.default_socket =/expertiza/tmp/sockets/mysql.sock文件中。

我做错了什么?

谢谢!

7 个答案:

答案 0 :(得分:37)

您需要follow the directions来安装和启动服务器。

该命令因MySQL安装方式而异。先试试这个:

  

sudo / Library / StartupItems / MySQLCOM / MySQLCOM start

如果失败:

  

cd / usr / local / mysql
  sudo ./bin/mysqld_safe
  (如有必要,请输入您的密码)
  (按Control-Z)
  BG

答案 1 :(得分:32)

另外,如果你遇到这个错误并通过Homebrew安装了mysql,我发现这有效(虽然你需要将“5.6.12”更改为你自己的版本):

  

/usr/local/Cellar/mysql/5.6.12/bin/mysql.server restart

我刚在我的主目录中创建了一个〜/ restartMysql.sh文件(上面只有上面的行),这样我就可以在MySQL执行时使用它

答案 2 :(得分:17)

在命令行上运行以下命令:

$ mysql.server start

答案 3 :(得分:4)

post为我做了帮助,我将重写这里的步骤(注意:我也将编写命令的输出......只是为了让你知道你正在进行中)< / p>

如果正在运行,请先停止服务器:

[root@servert1 ~]# /etc/init.d/mysqld stop
Stopping MySQL: [ OK ]

在单独的线程上运行sql dameon

[root@servert1 ~]# mysqld_safe --skip-grant-tables &    
[1] 13694    
[root@servert1 ~]# Starting mysqld daemon with databases from /var/lib/mysql

打开一个单独的shell窗口并输入

[root@servert1 ~]# mysql -u root

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

Your MySQL connection id is 1

Server version: 5.0.77 Source distribution



Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

开始使用mysql

mysql> use mysql; 

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A



Database changed

使用您的新密码手动更新user表格(注意:请随时输入mysql> show tables; 以获取您所在位置的视角)

注意:从MySQL 5.7密码位于authenication_string表中,因此命令为update user set authentication_string=password('testpass') where user='root';

mysql> update user set password=PASSWORD("testpass") where User='root';

Query OK, 3 rows affected (0.05 sec)

Rows matched: 3 Changed: 3 Warnings: 0

刷新权限(我不确定这些权限是什么......但它确实有效)

mysql> flush privileges; 

Query OK, 0 rows affected (0.04 sec)

退出

mysql> quit

Bye

停止服务器

注意:在OS X或macOS上,mysql.server位于/usr/local/mysql/support-files/

mysql.server stop

Shutting down MySQL
.130421 09:27:02 mysqld_safe mysqld from pid file /usr/local/var/mysql/mycomputername.local.pid ended
 SUCCESS! 
[2]-  Done                    mysqld_safe --skip-grant-tables

杀死运行dameon的其他shell窗口(只是为了确保)

现在你很高兴!试试吧:

[root@servert1 ~]#  mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.10 Source distribution

Copyright (c) 2000, 2013, 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> 

完成!

答案 4 :(得分:1)

我希望这有助于某人。我得到了同样的错误,但似乎与其他人的原因截然不同。

我有2台CentOS机器。

我将my.cnf复制到新机器上,没有意识到我已经将旧机器升级到MySQL 5.6,并且新机器安装了5.5。当我注释掉仅5.6的指令时,MySQL按预期启动。 (现在我正在运行升级,因此我可以应用大量有用的innodb_buffer_pool_dump_at_shutdowninnodb_buffer_pool_load_at_startup指令)

我建议尝试一个最低限度的my.cnf。如果MySQL启动,那么你就找到了问题的根源。

答案 5 :(得分:0)

看起来您需要安装MySQL服务器,mysql网站上有安装包,或者您可以通过macports安装(我假设来自darwin11行)。 我通过端口安装了我的,插座位于/ opt / local / var / run / mysql5 /.

答案 6 :(得分:0)

在我的情况下,我没有设置正确的tmp文件夹。我最终得到了这些步骤:

1. cd /

2. ln -s private/tmp /tmp
相关问题