无法通过套接字/tmp/ MySQL连接到本地MySQL服务器。袜子”(2)

时间:2022-12-14 03:55:41

I am trying to run mysql client on my terminal. I have installed the latest mysql gem.

我试图在我的终端上运行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# 

I am not able to get rid of the above error. I have created a mysql.sock file in /Users/HPV/expertiza/tmp/sockets. In the file I have written mysql.default_socket =/expertiza/tmp/sockets/mysql.sock.

我无法摆脱上面的错误。我创建了一个mysql。袜子文件/用户/人乳头状瘤病毒/ expertiza / tmp /套接字。在文件中,我写了mysql.default_socket =/expertiza/tmp/sockets/mysql.sock。

What am I doing wrong?

我做错了什么?

Thanks!

谢谢!

7 个解决方案

#1


36  

You need to follow the directions to install and start the server.

您需要按照指示安装和启动服务器。

The command varies depending on how you installed MySQL. Try this first:

该命令取决于您如何安装MySQL。试试这个:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

sudo /图书馆/ StartupItems / MySQLCOM / MySQLCOM开始

If that fails:

如果失败:

cd /usr/local/mysql
sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
bg

cd /usr/local/mysql sudo ./bin/mysqld_safe(输入密码,如果需要)(按Control-Z) bg。

#2


31  

Also, if you got this error and installed mysql via Homebrew, I found that this works (though you need to change "5.6.12" to your own version):

另外,如果您有这个错误,并通过Homebrew安装了mysql,我发现这是可行的(尽管您需要将“5.6.12”更改为您自己的版本):

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

/usr/local/Cellar/mysql/5.6.12/bin/mysql.服务器重启

I just created a file ~/restartMysql.sh in my home directory (with only the line above in it) so that I can just use this whenever MySQL is acting up

我刚刚创建了一个文件~/restartMysql。在我的主目录中(只包含上面的一行),这样当MySQL出现问题时,我就可以使用它。

#3


9  

Run the following on the command line :

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

$ mysql.server start

#4


4  

this post helped did it for me, I'll rewrite the steps here (note: i'll be also writing the output of your commands.. just so that you know you're on track)

这篇文章帮助了我,我将重写这里的步骤(注意:我也将编写您的命令的输出。只是为了让你知道你已经步入正轨了

first stop the server if running:

如果运行:首先停止服务器:

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

run an sql dameon on a separate thread

在单独的线程上运行sql dameon。

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

open a separate shell window and type

打开一个单独的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.

start using mysql

开始使用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

update the user table manually with your new password (note: feel free to type mysql> show tables; just to get a perspective on where you are)

用你的新密码手动更新用户表(注意:请随意输入mysql>显示表;只是想了解一下你在哪里)

NOTE: from MySQL 5.7 passwords are in the authenication_string table, so the command is update user set authentication_string=password('testpass') where user='root';

注意:从MySQL 5.7密码在authenication_string表中,所以命令是更新用户设置authentication_string=password('testpass'),其中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

flush privileges (i'm not sure what this privileges is all about.. but it works)

刷新特权(我不确定这些特权是什么)。但它的工作原理)

mysql> flush privileges; 

Query OK, 0 rows affected (0.04 sec)

quit

辞职

mysql> quit

Bye

stop the server

停止服务器

NOTE: on OS X or macOS, mysql.server is located at /usr/local/mysql/support-files/.

注意:在OS X或macOS上,mysql。服务器位于/usr/ local/mysql/supportfiles /。

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

kill the other shell window that has the dameon running (just to make sure)

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

now you are good to go! try it:

现在你可以走了!试一试:

[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> 

done!

完成了!

#5


1  

I hope this helps somebody. I was getting the same error, but seemingly for a much different reason than other people.

我希望这能帮助别人。我也犯了同样的错误,但似乎和其他人有很大不同。

I have 2 CentOS machines.

我有两个CentOS的机器。

I copied my.cnf to the new machine, not realizing that I had upgraded the old machine to MySQL 5.6, and the new machine had 5.5 installed. When I commented out the 5.6-only directives, MySQL started as expected. (and now I am running the upgrade so I can apply the massively useful innodb_buffer_pool_dump_at_shutdown and innodb_buffer_pool_load_at_startup directives)

我将my.cnf复制到新机器上,并没有意识到我已经将旧机器升级到MySQL 5.6,而新机器安装了5.5个。当我注释掉5.6的指令时,MySQL就像预期的那样开始了。(现在我正在运行升级,所以我可以应用大量有用的innodb_buffer_pool_dump_at_shutdown和innodb_buffer_pool_load_at_startup指令)

I would suggest trying a bare minimum my.cnf. If MySQL starts up, then you've found the source of your problem.

我建议尝试一下最小的my.cnf。如果MySQL启动,那么您就找到了问题的根源。

#6


0  

It looks like you need a MySQL server installed, there is install packages on mysql's site, or you can install through macports (I assume from the darwin11 line). I installed mine via ports, and the socket lives in /opt/local/var/run/mysql5/.

看起来您需要安装一个MySQL服务器,在MySQL的站点上安装软件包,或者您可以通过macports安装(我假设从达尔文的路线)。我是通过端口安装的,而套接字生活在/opt/local/var/运行/mysql5/。

#7


0  

In my case, I don't got tmp folder setting up right. What I end up with these steps:

在我的例子中,我没有把tmp文件夹设置正确。我最后的步骤是:

1. cd /

2. ln -s private/tmp /tmp

#1


36  

You need to follow the directions to install and start the server.

您需要按照指示安装和启动服务器。

The command varies depending on how you installed MySQL. Try this first:

该命令取决于您如何安装MySQL。试试这个:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

sudo /图书馆/ StartupItems / MySQLCOM / MySQLCOM开始

If that fails:

如果失败:

cd /usr/local/mysql
sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
bg

cd /usr/local/mysql sudo ./bin/mysqld_safe(输入密码,如果需要)(按Control-Z) bg。

#2


31  

Also, if you got this error and installed mysql via Homebrew, I found that this works (though you need to change "5.6.12" to your own version):

另外,如果您有这个错误,并通过Homebrew安装了mysql,我发现这是可行的(尽管您需要将“5.6.12”更改为您自己的版本):

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

/usr/local/Cellar/mysql/5.6.12/bin/mysql.服务器重启

I just created a file ~/restartMysql.sh in my home directory (with only the line above in it) so that I can just use this whenever MySQL is acting up

我刚刚创建了一个文件~/restartMysql。在我的主目录中(只包含上面的一行),这样当MySQL出现问题时,我就可以使用它。

#3


9  

Run the following on the command line :

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

$ mysql.server start

#4


4  

this post helped did it for me, I'll rewrite the steps here (note: i'll be also writing the output of your commands.. just so that you know you're on track)

这篇文章帮助了我,我将重写这里的步骤(注意:我也将编写您的命令的输出。只是为了让你知道你已经步入正轨了

first stop the server if running:

如果运行:首先停止服务器:

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

run an sql dameon on a separate thread

在单独的线程上运行sql dameon。

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

open a separate shell window and type

打开一个单独的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.

start using mysql

开始使用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

update the user table manually with your new password (note: feel free to type mysql> show tables; just to get a perspective on where you are)

用你的新密码手动更新用户表(注意:请随意输入mysql>显示表;只是想了解一下你在哪里)

NOTE: from MySQL 5.7 passwords are in the authenication_string table, so the command is update user set authentication_string=password('testpass') where user='root';

注意:从MySQL 5.7密码在authenication_string表中,所以命令是更新用户设置authentication_string=password('testpass'),其中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

flush privileges (i'm not sure what this privileges is all about.. but it works)

刷新特权(我不确定这些特权是什么)。但它的工作原理)

mysql> flush privileges; 

Query OK, 0 rows affected (0.04 sec)

quit

辞职

mysql> quit

Bye

stop the server

停止服务器

NOTE: on OS X or macOS, mysql.server is located at /usr/local/mysql/support-files/.

注意:在OS X或macOS上,mysql。服务器位于/usr/ local/mysql/supportfiles /。

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

kill the other shell window that has the dameon running (just to make sure)

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

now you are good to go! try it:

现在你可以走了!试一试:

[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> 

done!

完成了!

#5


1  

I hope this helps somebody. I was getting the same error, but seemingly for a much different reason than other people.

我希望这能帮助别人。我也犯了同样的错误,但似乎和其他人有很大不同。

I have 2 CentOS machines.

我有两个CentOS的机器。

I copied my.cnf to the new machine, not realizing that I had upgraded the old machine to MySQL 5.6, and the new machine had 5.5 installed. When I commented out the 5.6-only directives, MySQL started as expected. (and now I am running the upgrade so I can apply the massively useful innodb_buffer_pool_dump_at_shutdown and innodb_buffer_pool_load_at_startup directives)

我将my.cnf复制到新机器上,并没有意识到我已经将旧机器升级到MySQL 5.6,而新机器安装了5.5个。当我注释掉5.6的指令时,MySQL就像预期的那样开始了。(现在我正在运行升级,所以我可以应用大量有用的innodb_buffer_pool_dump_at_shutdown和innodb_buffer_pool_load_at_startup指令)

I would suggest trying a bare minimum my.cnf. If MySQL starts up, then you've found the source of your problem.

我建议尝试一下最小的my.cnf。如果MySQL启动,那么您就找到了问题的根源。

#6


0  

It looks like you need a MySQL server installed, there is install packages on mysql's site, or you can install through macports (I assume from the darwin11 line). I installed mine via ports, and the socket lives in /opt/local/var/run/mysql5/.

看起来您需要安装一个MySQL服务器,在MySQL的站点上安装软件包,或者您可以通过macports安装(我假设从达尔文的路线)。我是通过端口安装的,而套接字生活在/opt/local/var/运行/mysql5/。

#7


0  

In my case, I don't got tmp folder setting up right. What I end up with these steps:

在我的例子中,我没有把tmp文件夹设置正确。我最后的步骤是:

1. cd /

2. ln -s private/tmp /tmp