Tag: mysql

Mysql import将timestamp空值转换为0000-00-00 00:00:00

我有一些文本文件 – 定期生成 – 其中包含要使用mysqlimport插入mysql的sql行。 其中一列具有Null值,数据库中的此列是日期时间字段,默认值设置为Null。 但是在运行mysql导入之后,我在这个专栏中得到了值00:00:00,那我怎么能摆脱这个呢? 我希望列值在插入时为Null。 编辑 :备注: 1)使用INSERT语句直接插入行时,不会发生此问题,并且列值通常设置为NULL,因此这与mysqlimport 2)我使用mysqlimport: mysqlimport -u root -p -h localhost –columns=” –local –fields-terminated-by=’,’ 3)数据文件中一行的样本: 5964,45,0,0,NULL,45,5,8,67869,67848,65142,1,NULL,NULL,NULL,19 4)datetime列是通过rails迁移创建的rails timestamp created_at 。

MySQL / Rails查找方法中的歧义列

我收到了这个错误 Mysql :: Error:字段列表中的列’id’不明确 当使用像这样的find方法时: self.prompts.find(:all, :select => ‘id’) 使用has_many:through关联调用模型,因此MySQL抱怨有多个’id’列,因为所有使用的3个表都有’id’列。 我查了一下,了解SQL端出了什么问题,但不知道如何在ActiveRecord find方法中解决它,而且我对自己的SQL能力没有信心尝试滚动自己的SQL查询。 有没有办法将find方法按到能够发挥出色的效果? 编辑 这是相关的Actor模型代码: class Actor :destroy has_many :decisions, :through => :acts, :order => ‘created_at’ has_many :prompts, :through => :decisions, :order => ‘id’

Rails activerecord:sum,max和join

我有两个模型users和posts 。 用户可以投票和查看post #users id name #posts id count_votes count_views users_id created_at updated_at 我希望过去24小时内收到最多票数和观点的用户。 最大的观点和投票总和获胜。 我做了什么我有这个SQL查询,它很好,但我想让用户获得最多的投票,这个给我所有用户,我不知道如何添加count_views select u.name as “Name”, sum(p.count_votes) from posts p inner join users u on p.user_id = u.id where p.created_at >= DATE_SUB(NOW(), INTERVAL 1 day) group by user_id; ActiveRecord版本 Post.select(“users.id, sum(posts.count_votes) as nb_votes”) .joins(:user).where(“posts.created_at >= ?”, 1.day.ago.beginning_of_day) .group(“posts.user_id”) # Results on […]

Rails:每个http请求都会创建一个新的连接池吗?

我正在阅读这篇文章https://polycrystal.org/posts/2012-05-25-active-record-connection-pool-fairness.html ,它说明每个http reuest都会创建一个新的连接池。 这是真的吗? 如果确实如此,那么如果http请求创建需要访问数据库的两个线程,那么两个线程将创建两个单独的连接池agian,或者它们将使用由http请求创建的连接池。 谢谢,

如何将mysql数据库文件连接到rails应用程序上的本地ruby

我有一个数据库文件(name.sql)发送给我,我应该连接到我的Mac本地托管的rails应用程序,我从github下载(分叉?)。 如何设置我的database.yml文件以连接sql文件。

Rails和MySQL语法错误与执行块中的多个SQL语句

对于使用MySQL的应用程序,我在Rails迁移中有以下代码: execute <<-SQL ALTER TABLE properties ADD name VARCHAR(255) NOT NULL; ALTER TABLE properties ADD CONSTRAINT fk_properties_name FOREIGN KEY (name) REFERENCES valid_property_names (property_name); SQL 当我运行迁移时,我收到以下错误: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ALTER TABLE properties 为什么我会收到此错误,如何解决?

mysql2 gem安装失败

我的堆栈如下: CentOS 6.3 已安装MySQL 5.5(按照http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/中的步骤操作,因为yum仍然具有MySQL 5.1和如果我尝试yum安装任何与mysql相关的软件包,它当然会因为yum所期望的而破坏5.1) $> mysql –version mysql Ver 14.14使用readline 5.1为Linux(x86_64)分发5.5.27 $> ruby​​ –version ruby​​ 1.9.3p194(2012-04-20修订版35410)[x86_64-linux] $> rvm –version rvm 1.14.6(稳定)作者:Wayne E. Seguin,Michal Papis [https://rvm.io/] $> uname -a Linux localhost.mkf 2.6.32-279.5.1.el6.x86_64#1 SMP Tue Tue Aug 14 23:54:45 UTC 2012 x86_64 x86_64 x86_64 GNU / Linux $> nginx -v nginx版本:nginx / 1.2.2 $> rails […]

执行Bundle安装时MySql出错

当我执行Bundle Install时,出现以下错误: Installing mysql2 (0.3.10) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/manish/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb checking for rb_thread_blocking_region()… yes checking for rb_wait_for_single_fd()… no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need […]

LOAD DATA LOCAL INFILE使用mysql2 gem导致格式错误的数据包错误

我正在尝试发出一个LOAD DATA LOCAL INFILE查询,使用rails 3.1.1下的mysql2 gem(0.3.11)将一些CSV数据加载到表中: class Foo < ActiveRecord::Base def self.load_csv query = "LOAD DATA LOCAL INFILE 'test/foo.csv' REPLACE INTO TABLE foos LINES TERMINATED BY '\n' (title)" ActiveRecord::Base.connection.execute(query) end end (这是一个重现此github问题的错误的示例应用程序)。 这在OS X(Lion)上出现故障,并出现以下错误: Mysql2::Error: Malformed packet: LOAD DATA LOCAL INFILE ‘test/foo.csv’ REPLACE INTO TABLE foos LINES TERMINATED BY ‘ ‘ (title) 服务器上启用了本地infile: mysql> show […]

Windows中的Heroku安装错误

我在我的Windows机器上安装了Heroku工具带。 但执行heroku login我收到以下错误: “MySQL”不被识别为内部或外部命令,可操作程序或批处理文件。 “MySQL”不被识别为内部或外部命令,可操作程序或批处理文件。 ! Git must be installed to use the Heroku Toolbelt. ! See instructions here: http://git-scm.com 我已经安装了git,MySQL和所有正在使用cmd的工作,我的rails应用程序在我的localhost上正常工作。 奇怪的是为什么heroku甚至使用mysql,因为我只是登录。如何解决这个问题?