无法通过套接字“/tmp/mysql.sock”连接到本地MySQL服务器(2)
我正在尝试在我的终端上运行 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#
我无法摆脱上述错误。我在 /Users/HPV/expertiza/tmp/sockets
中创建了一个 mysql.sock 文件
。在文件中我编写了mysql.default_socket =/expertiza/tmp/sockets/mysql.sock
。
我做错了什么?
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您需要按照说明安装并启动服务器。
该命令根据您安装 MySQL 的方式而有所不同。首先尝试这个:
如果失败:
You need to follow the directions to install and start the server.
The command varies depending on how you installed MySQL. Try this first:
If that fails:
另外,如果您遇到此错误并通过 Homebrew 安装了 mysql,我发现这可以工作(尽管您需要将“5.6.12”更改为您自己的版本):
我刚刚在我的主目录中创建了一个文件 ~/restartMysql.sh (其中只有上面的行),这样我就可以在任何时候使用它MySQL 正在运行
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):
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
在命令行上运行以下命令:
Run the following on the command line :
这 post 帮助我完成了这件事,我将在这里重写这些步骤(注意:我还将编写您的命令的输出..只是为了让您知道你已经步入正轨)
如果正在运行,首先停止服务器:
在单独的线程上运行 sql 守护进程
打开一个单独的 shell 窗口并输入
< em>开始使用 mysql
使用新密码手动更新
user
表(注意:随意输入mysql> showtables;
只是为了了解您所在的位置)注意:从 MySQL 5.7 开始,密码位于
authenication_string
表中,因此命令是update user setauthentication_string=password ('testpass') where user='root';
刷新权限(我不确定这个权限是什么......但它有效)
退出
停止服务器
注意:在 OS X 或 macOS 上,
mysql.server
位于/usr/local/mysql/support-files/
。杀死正在运行守护进程的其他 shell 窗口(只是为了确保)
现在就可以开始了!尝试一下:
完成!
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:
run an sql dameon on a separate thread
open a separate shell window and type
start using mysql
update the
user
table manually with your new password (note: feel free to typemysql> show tables;
just to get a perspective on where you are)NOTE: from MySQL 5.7 passwords are in the
authenication_string
table, so the command isupdate user set authentication_string=password('testpass') where user='root';
flush privileges (i'm not sure what this privileges is all about.. but it works)
quit
stop the server
NOTE: on OS X or macOS,
mysql.server
is located at/usr/local/mysql/support-files/
.kill the other shell window that has the dameon running (just to make sure)
now you are good to go! try it:
done!
我希望这对某人有帮助。我遇到了同样的错误,但似乎与其他人有很大不同的原因。
我有 2 台 CentOS 机器。
我将my.cnf复制到新机器上,没有意识到我已经将旧机器升级到MySQL 5.6,而新机器安装了5.5。当我注释掉仅 5.6 的指令时,MySQL 按预期启动。 (现在我正在运行升级,以便我可以应用非常有用的
innodb_buffer_pool_dump_at_shutdown
和innodb_buffer_pool_load_at_startup
指令)我建议尝试最少的 my.cnf。如果 MySQL 启动,那么您就找到了问题的根源。
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.
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
andinnodb_buffer_pool_load_at_startup
directives)I would suggest trying a bare minimum my.cnf. If MySQL starts up, then you've found the source of your problem.
看起来你需要安装一个 MySQL 服务器,mysql 的网站上有安装包,或者你可以通过 macports 安装(我假设是来自 darwin11 行)。
我通过端口安装了我的,套接字位于 /opt/local/var/run/mysql5/ 中。
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/.
就我而言,我没有正确设置 tmp 文件夹。我通过这些步骤最终得到了什么:
In my case, I don't got tmp folder setting up right. What I end up with these steps: