Mac OS 10.10 php不能连接mysql问题解决

WBOY
Freigeben: 2016-06-23 13:37:22
Original
949 Leute haben es durchsucht

php连接数据库都没问题,升级到10.10这后, 突然连接不上了. 这个问题放了很久, 今天突然搜索到一篇文章.

用链接的方式解决了. 原文如下:

So you installed Ubuntu, got all excited about developing your Rails application on it, and then…

No such file or directory - /tmp/mysql.sock)
Nach dem Login kopieren

No matter what you do, database connection doesn’t work. You reinstall Rails (of course you installed it via “sudo apt-get rails”, right??), reinstall MySql, recreate the database schema, change root’s password, install Kubuntu instead of Ubuntu… But it doesn’t work.

The reason for this error is quite simple, really: somewhere along Ruby’s Mysql driver, mysql socket is expected to exist at /tmp/mysql.sock. But that’s not where it is in Ubuntu. If you take some time searching, you’ll notice that the .sock file is actually on /var/run/mysqld - and it’s called mysqld.sock instead.

In fact, if you Google it, there is a closed bug entry on Rails’ tracking system regarding that problem, and the suggested solution there is to change your database.yml to add a link to the correct socket. Something like:

production:  adapter: mysql  socket: /var/run/mysqld/mysqld.sock
Nach dem Login kopieren

Which is obviously not a good idea, since you’ll end up creating new projects, moving to a different OS or whatever - and everything will break again.

So I tried a small patchwork to fool mysql’s driver, and then it works nicely:

sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
Nach dem Login kopieren

That way you will actually HAVE a /tmp/mysql.sock file, as expected by mysql driver, and everything will connect just fine. Just like it’s meant to be. Amen!

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage