MacOS10.10php不能连接mysql问题解决_MySQL
用链接的方式解决了. 原文如下:
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!
上一篇: php 使用html5实现多文件上传实例
推荐阅读
-
JDBC连接mysql乱码异常问题处理总结
-
Python连接mysql数据库及python使用mysqldb连接数据库教程
-
JDBC连接MySQL5.7的方法
-
log引起的mysql不能启动的解决方法
-
myeclipse连接mysql数据库详细步骤(实战mysql数据库引擎)
-
详解MySQL数据库--多表查询--内连接,外连接,子查询,相关子查询
-
MySql学习day03:数据表之间的连接、查询详解
-
详解使用navicat连接远程linux mysql数据库出现10061未知故障
-
Spring Boot 与 Kotlin 使用JdbcTemplate连接MySQL数据库的方法
-
python连接mysql调用存储过程示例