Mac OS 10.10 php不能连接mysql问题解决
2015-04-03 22:40
489 查看
php连接数据库都没问题,升级到10.10这后, 突然连接不上了. 这个问题放了很久, 今天突然搜索到一篇文章.
用链接的方式解决了. 原文如下:
So you installed Ubuntu, got all excited about developing your Rails application on it, and then…
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:
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:
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!
用链接的方式解决了. 原文如下:
So you installed Ubuntu, got all excited about developing your Rails application on it, and then…
No such file or directory - /tmp/mysql.sock)
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
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
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!
相关文章推荐
- MYSQL+PHP5.2.17+IIS5.1不能连接数据库问题解决方法
- 解决ubuntu下mysql不能远程连接数据库的问题
- [ASP/PHP/JSP]MySQL5.0中文问题及JDBC数据库连接和JSP汉字编码问题解决方法总结
- 解决没有安装Qt 的mysql sql驱动插件情况下不能连接数据库的问题
- Mac os 解决无法使用localhost连接mysql问题
- 解决ubuntu下mysql不能远程连接数据库的问题
- 怎样解决数据库 Navicat 8for MySQL中不能连接到本地数据库的问题啊??请大虾们帮忙
- 解决php5.3不能连接mssql数据库问题
- 解决ubuntu下mysql不能远程连接数据库的问题
- Linux下phpmyadmin不能登录连接MySQL,且无任何提示的问题解决方法
- 【PHP问题大全】--PHP连接MySQL出现乱码的编码解决办法
- 解决不能通过mysql.sock连接MySQL问题
- mysql 由于权限问题远程不能连接,解决方法
- 解决mysql不能和php连接,并提示1251错误
- mysql 1130 远程不能连接问题解决
- Ubuntu下MySQL不能连接问题的解决 MESSAGE: java.net.ConnectException: Connection refused
- 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。
- CentOS下php使用127.0.0.1不能连接mysql的解决方法
- 解决不能通过mysql.sock连接MySQL问题
- 解决ubuntu下mysql不能远程连接数据库的问题