多谢,已解决!答案见下面的回复!谢谢!
执行创建数据库命令时
deployer@vps:~/depot$ rake db:create RAILS_ENV=production
报如下错误
deployer@vps:~/depot$ rake db:create RAILS_ENV=production
Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock=' (2)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"depot_production", "pool"=>5, "username"=>"root", "password"=>"abc", "socket"=>"/var/run/mysqld/mysql.sock"}, charset: utf8, collation:
(if you set the charset manually, make sure you have a matching collation)
config/database.yml 文件的配置如下:
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_production
pool: 5
username: root
password: abc
socket: /var/run/mysqld/mysql.sock
另外,检查了/var/run/mysqld 目录下的文件
deployer@vps:/var/run/mysqld$ ll
total 4
drwxr-xr-x 2 mysql root 80 May 9 11:51 ./
drwxr-xr-x 15 root root 520 May 9 10:38 ../
-rw-rw---- 1 mysql mysql 5 May 9 11:51 mysqld.pid
srwxrwxrwx 1 mysql mysql 0 May 9 11:51 mysqld.sock=
这里的 mysqld.sock=名称有点诡异,不知道为啥会有了=?重启后,还是这样。
另外,检查了/etc/mysql/my.cnf,内容如下:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = 127.0.0.1
MySQL 版本信息如下:
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.5.31-0ubuntu0.12.04.1 |
+-------------------------+
1 row in set (0.00 sec)
deployer@vps:/var/run/mysqld$ mysql --version
mysql Ver 14.14 Distrib 5.5.31, for debian-linux-gnu (x86_64) using readline 6.2
Ubuntu 版本信息如下:
deployer@vps:/var/run/mysqld$ clear
deployer@vps:/var/run/mysqld$ uname -a
Linux vps 2.6.32-042stab076.5 #1 SMP Mon Mar 18 20:41:34 MSK 2013 x86_64 x86_64 x86_64 GNU/Linux
deployer@vps:~$ head -n 1 /etc/issue
Ubuntu 12.04.1 LTS \n \l
已经重启过,还是不行!
求解答!更求解释!
StackOverflow 也有人提到这个问题
http://stackoverflow.com/questions/13666560/rails3-mysql2-rake-error 这里遇到的问题一样。不过,没人解决。