MySQL在我的Rails应用程序中没有响应

时间:2013-07-03 16:24:42

标签: mysql ruby-on-rails activerecord

我正在尝试使用Ruby将文件加载到数据库中。它是一个大约15 Mb的大文件...它正确地复制了一段时间的记录....但是在复制了几条记录之后,没有错误但它没有将记录插入到数据库中.........当我在一个单独的控制台中连接到Msql提示符时...我收到一个错误:

mysql> desc testdb2.test_descriptions;
ERROR 2006 (HY000): MySQL server has gone away                                                                                                                                                                                                                                 
No connection. Trying to reconnect...                                                                                                                                                                                                                                          
Connection id:    52

之后我能够连接到Mysql数据库.......现在又是脚本开始将记录写入数据库......

在应用程序运行时,有没有办法维护与数据库的连接?

我不确定这是一种超时问题还是其他问题....请纠正我......

def simulate_datasets
    Log.initialize

      data_folders = ["Jun_06_2013"];
      data_folders.each do |data_folder|

        add(data_folder);
      end
      render :text => Log.dump
  end

def add (data_folder)
     @dataset  = Dataset.initialize
     @dataset.created_at=Date.new(2013,06,06)
     @dataset.save

     current_root = "script/datasets/"+data_folder+"/"
     strip_string = "/development/A/"
     population_time = {}
     total_time = 0

     clusters = Cluster.find(:all, :order=>"created_at DESC");
     if clusters.empty?
       Log.info "No Clusters found"
       Cluster.initialize
       clusters = Cluster.find(:all, :order=>"created_at DESC");
     end

     clusters.each do |cluster|
        cluster_path = cluster.path
        root = current_root + cluster.name+'/' 
        total_time += populate_file_or_folder(root+"fileListWithMLintMetrics.txt", cluster_path)
     end

end            

我使用populate_file_or_folder方法填充数据库

mysql> show variables like '%time%';
+----------------------------+-------------------+
| Variable_name              | Value             |
+----------------------------+-------------------+
| connect_timeout            | 10                |
| datetime_format            | %Y-%m-%d %H:%i:%s |
| delayed_insert_timeout     | 300               |
| flush_time                 | 0                 |
| innodb_lock_wait_timeout   | 50                |
| innodb_rollback_on_timeout | OFF               |
| interactive_timeout        | 28800             |
| lc_time_names              | en_US             |
| long_query_time            | 10.000000         |
| net_read_timeout           | 30                |
| net_write_timeout          | 60                |
| slave_net_timeout          | 3600              |
| slow_launch_time           | 2                 |
| system_time_zone           | EDT               |
| table_lock_wait_timeout    | 50                |
| time_format                | %H:%i:%s          |
| time_zone                  | SYSTEM            |
| timed_mutexes              | OFF               |
| timestamp                  | 1372869659        |
| wait_timeout               | 28800             |
+----------------------------+-------------------+
20 rows in set (0.00 sec)

def self.populate_file_or_folder(fileName, cluster_path)

    counter = 0                                                      
    # Reading directly from the CSV library
    CSV.foreach(fileName) do |line|
      counter = counter+1
      completePath = line[0]                                                
      completePath = cluster_path+ '/'+completePath

   newStructure = FileOrFolder.new
    newStructure.fullpath = path
    pathbits = path.split('/')
    newStructure.name = pathbits.last
    newStructure.save
    end
  end

0 个答案:

没有答案