Tag: mysql

如何迁移现有记录以匹配rails中的新ORM

最近我在我正在构建的应用程序中更改了模型关系。 由于稍后将部署这些更改,因此我需要知道如何将现有数据迁移到新结构。 这感觉就像一个可怕的前景。 我原来的设置是这样的.. 客户有很多地方 一个位置属于一个客户端 然后我创建了一个连接表,以便client has many locations through client_locations 。 所以从旧的数据结构我在locations数据库中有client_id。 如何将这些数据移动到新结构?

heroku rake db:migrate ERROR“gem install activerecord-mysql-adapter”

即时通讯使用Rails 3.2.6试图运行 heroku run rake db:migrate 我得到了adaptar错误 rake aborted! Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) 在我的database.yml中,我将开发,生产和测试设置为: adapter: mysql2 这是我的gem环境 ➜ my_app git:(master) gem env RubyGems Environment: – RUBYGEMS VERSION: 1.8.24 – RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2] – INSTALLATION DIRECTORY: /Users/jcollyer/.rvm/gems/ruby-1.9.3-p327 […]

如何使用Rails 2.1和MySQL定义BigInt主键?

从Rails 2.1开始,如果在迁移中定义一个新列,其类型设置为:integer,并且:limit设置为5或更多,则实际在MySQL数据库中创建的列将是BigInt类型。 那很完美。 但我无法弄清楚如何使用BigInt主键创建表。 有什么线索吗?

Heroku rake db:结构:用cleardb加载找不到’mysql’

我正在尝试在heroku dyno上安装Sharetribe的实例。 我正在尝试创建数据库。 我首先尝试了rake db:migrate,它适用于大多数迁移,但在其中一个迁移时失败了。 我被建议使用rake db:structure:load,所以我尝试了,我从Heroku得到一个错误,说mysql需要添加到PATH变量。 为什么会这样,我该如何解决? 我不确定它为什么会在db:schema:load和db:structure:load但不在db:migrate上发生。 带有错误消息的完整堆栈跟踪是: rake aborted! failed to execute: mysqlPlease check the output above for any errors and make sure that `mysql` is installed in your PATH and has proper permissions. /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/mysql_database_tasks.rb:148:in `run_cmd’ /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/mysql_database_tasks.rb:72:in `structure_load’ /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:189:in `structure_load’ /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:222:in `load_schema_for’ /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:236:in `block in load_schema_current’ /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:276:in `block in each_current_configuration’ /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:275:in `each’ […]

“MySQL客户端库版本不正确”

运行rake assets:precompile时出现以下错误rake assets:precompile Incorrect MySQL client library version! This gem was compiled for 5.6.10 but the client library is 5.5.12. MySQL使用Homebrew安装,版本为5.6.10。 我可以在本地连接到127.0.0.1上的数据库。 我试过以下没有运气: ARCHFLAGS=”-arch x86_64″ gem install mysql2 — –with-mysql-config=/usr/local/bin/mysql_config 似乎建议适用于那些“客户端库”比Gem编译的客户端更新的人。 我的问题恰恰相反。 无法弄清楚5.5.12的来源。 有任何想法吗?

Rails + Amazon RDS:延迟问题

我有一个应用程序,其数据库正在迁移到亚马逊RDS。 由于RDS和我们的服务器之间的查询延迟(因为查询只有30秒的加载时间),我的性能大幅下降。 没有明确的缓存,可以对请求进行更多优化,但这仍然比使用本地数据库慢10倍。 我预计这种性能会下降吗? 如果是,是否有办法使用具有与本地数据相似的云数据库?

Unicorns吃掉了不考虑池大小的MySQL连接–Rails

我为我的Rails应用程序运行了4个Unicorn进程,它们占用了所有可用的MySQL连接,导致它因“连接数太多”错误而崩溃。 今天我不得不重启我的数据库实例4次。 =( 流程 $ ps ax | grep [u] ni 21618? Sl 0:15独角兽大师-D -c /home/deployer/apps/XXX/shared/config/unicorn.rb -E production 21632? Sl 0:20独角兽工[0] -D -c /home/deployer/apps/XXX/shared/config/unicorn.rb -E production 21636? Sl 0:14独角兽工[1] -D -c /home/deployer/apps/XXX/shared/config/unicorn.rb -E production 21640? Sl 0:20独角兽工[2] -D -c /home/deployer/apps/XXX/shared/config/unicorn.rb -E production 21645? Sl 0:12独角兽工[3] -D -c /home/deployer/apps/XXX/shared/config/unicorn.rb -E production 我的database.yml为ActiveRecord池设置了22个连接…… … 生产: 适配器:mysql2 编码:utf8 […]

包含,选择,排序,限制多个模型(单个查询)

我需要创建一个包含以下表中数据的查询: *对话 :在用户之间对消息进行分组的模型 class Conversation :conversation_participants ## Attributes title, created_at, updated_at end * ConversationParticipant :跟踪对话用户的模型 class ConversationParticipant < ActiveRecord::Base ## Associations belongs_to :conversation belongs_to :user ## Attributes conversation_id, user_id, seen, created_at, updated_at end *消息 :保持跟踪内容和发件人的模型 class Message “User” ## Attributes sender_id, content, conversation_id, created_at, updated_at end *用户 :具有属性name的模型 如何在单个查询中获取以下内容? (5)来自uniq Conversation 消息的最近消息的限制 来自ConversationParticipant的 user_id = […]

选择* sql query vs选择特定列sql查询

可能重复: 为什么SELECT *被认为有害? 可能是一个数据库nOOb问题。 我们的应用程序有如下表格 表WF Field | Type | Null | Key | Default | Extra | +——————–+————-+——+—–+———+—————-+ | id | int(11) | NO | PRI | NULL | auto_increment | | children | text | YES | | NULL | | | w_id | int(11) | YES | | NULL | | | […]

在生产模式下获取“拒绝用户’root’@’localhost’(使用密码:NO)”并且没有记录错误

我部署了我的Rails应用程序,并且在所有页面上都出现了500个错误。 我的production.log没有显示任何内容(这是一个问题),但我做了’脚本/控制台生产’并试图运行一个简单的查询(User.find:first),它抛出这个: Access denied for user ‘root’@’localhost’ (using password: NO) 我的database.yml文件肯定有一个密码,这是正确的。 所以,加上没有错误记录到我的production.log文件让我想知道是什么。 我开始寻找的任何想法或问题是什么? 此外,为了它的价值,我在Apache上运行Passenger。 更新:这是我的database.yml文件内容 development: adapter: mysql encoding: utf8 database: website_development username: root password: secretz socket: /tmp/mysql.sock test: adapter: mysql encoding: utf8 database: website_test username: root password: secretz socket: /tmp/mysql.sock production: adapter: mysql encoding: utf8 database: website_production username: ttp_mysql password: secretz socket: /var/run/mysqld/mysqld.sock 新更新:我更改了mysql用户,因此它没有在root中运行,但现在我仍然得到“访问被拒绝’root’@’localhost’”位…即使在生产模式下它也不应该完全按照’root’运行。 […]