SELECT table_schema "DB Name", sum( data_length + index_length ) / 1024 / 1024 "DB Size in MB"
FROM information_schema.TABLES GROUP BY table_schema ;
Courtesy: http://stackoverflow.com/questions/1733507/how-to-get-size-of-mysql-database
SELECT table_schema "DB Name", sum( data_length + index_length ) / 1024 / 1024 "DB Size in MB"
FROM information_schema.TABLES GROUP BY table_schema ;
Courtesy: http://stackoverflow.com/questions/1733507/how-to-get-size-of-mysql-database
and i forgot to install libmysqlclient-dev :) how careless! so didGem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/praveen/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... noand much more
`dump': no marshal_dump is defined for class Mysql (TypeError
require "rubygems"
require "mysql"
class RandomClass
def initialize
@db_instance = Mysql.real_connect("hostname", "username", "password", "database_name")
end
end
random_class = RandomClass.new
a = Marshal.dump(random_class)
require "rubygems"
require "mysql"
class RandomClass
def initialize
db_instance = Mysql.real_connect("hostname", "username", "password", "database_name")
db_instance.close
end
end
random_class = RandomClass.new
a = Marshal.dump(random_class)
mysqldump -u some_user -psome_password xxxxxxxxx_blog > xxxxxxxxx_blog.dump.sql
mysqldump: Got error: 145: Table './xxxxxxxxx_blog/xxxxxxxxxblog_options' is marked as crashed and should be repaired when using LOCK TABLES
sudo myisamchk -r ./xxxxxxxxx_blog/xxxxxxxxxblog_options
- recovering (with sort) MyISAM-table './xxxxxxxxx_blog/xxxxxxxxxblog_options'
Data records: 210
- Fixing index 1
- Fixing index 2
Data records: 208
class SourceDB < ActiveRecord::BaseendSourceDB.establish_connection($config["database_mysql"])
class TargetDB < ActiveRecord::BaseendTargetDB.establish_connection($config["database_sqlite"])
File.open(name_of_schema_file,"w") do |file|ActiveRecord::SchemaDumper.dump(SourceDB.connection, file)end
ActiveRecord::Base.connection = TargetDB.connectionload(name_of_schema_file)
require 'rubygems'require 'active_record'require 'active_support'require 'sqlite3'require 'active_record/schema_dumper'require "yaml"require "create_class.rb"t1 = Time.now$config = YAML.load_file("config/config.yml")name_of_schema_file = ($config["schema_file"])class SourceDB < ActiveRecord::BaseendSourceDB.establish_connection($config["database_mysql"])class TargetDB < ActiveRecord::BaseendTargetDB.establish_connection($config["database_sqlite"])puts "dumping the schema"File.open(name_of_schema_file,"w") do |file|ActiveRecord::SchemaDumper.dump(SourceDB.connection, file)endputs "discarding index(es)"line_array = Array.newFile.open(name_of_schema_file,"r") do |file|file.each { |line| line_array << line unless line.include?("add_index")}endFile.rename(name_of_schema_file, "original_#{name_of_schema_file}")File.open(name_of_schema_file,"w") do |file|file.puts(line_array)endputs "loading the schema"ActiveRecord::Base.connection = TargetDB.connectionload(name_of_schema_file)SourceDB.connection.tables.each do |tbl|puts "Table_initiated: #{tbl.inspect}"SourceDB.set_table_name tblSourceDB.set_inheritance_column ""create_class('TargetModel', TargetDB) doset_table_name tblset_inheritance_column ""endputs "=========for table: #{tbl}=========="total_record_in_table = SourceDB.count_by_sql("SELECT COUNT(*) from #{tbl}")tub_size = 1000no_of_iteration = ((total_record_in_table % tub_size) == 0) ? (total_record_in_table / tub_size) : ((total_record_in_table / tub_size) + 1)for j in 0..(no_of_iteration-1)current_record_set = SourceDB.find(:all,:offset => (j*tub_size), :limit => (tub_size - 1))current_record_set.each_with_index do |record,ind|record_copy = TargetModel.newrecord.attributes.each do |key,value|record_copy.send("#{key}=",value)endrecord_copy.saveputs "Completed: #{((j*tub_size) + ind)} of #{total_record_in_table} with id: #{record_copy.id} ."endendendt2 = Time.nowputs "Process initiated at: #{t1}"puts "Process completed at: #{t2}"puts "Time elapsed : #{t2-t1} seconds"
def create_class(class_name, superclass, &block)klass = Class.new superclass, &blockObject.const_set class_name, klassend
database_mysql:adapter: mysqldatabase: databse_nameusername: rootpassword: xxxxxxxxhost: xxx.xx.x.xxxtimeout: 5000encoding: utf8database_sqlite:adapter: sqlite3database: sqlite_database_file_with_path.dbschema_file: schema.txt
Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...