MySQL: Check size of DB
Posted . Visible to the public.
SELECT table_schema 'DB Name',
round(Sum(data_length + index_length) / 1024 / 1024, 1) 'DB size in MB'
FROM information_schema.tables
GROUP BY table_schema;
Related cards:
MySQL: Database Size
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;
MySql: Backup and Restore DB
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
MongoDB: List all collections by size
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(sta...
Mongo DB Querying
Count number of records in array:
db.data_records.count( { dataset_id: { $in: [ 2509, 2224, 2128, 2145, 2472, 2249 ] } } )
Count number of records NOT in array:
db.data_records.count( { dataset_id: { $nin: [ 2509, 2224, 2128, 2145, 2472, 2249...
Linux: Change Owner/Group of File
EXAMPLES
chown root /u
Change the owner of /u to "root".
chown root:staff /u
Likewise, but also change its group to "staff".
chown -hR root /u
Change the owner of /u and subfiles to "root".
MySQL: Auto Increment
SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "databaseName"
AND TABLE_NAME = "tableName"
alter table tablename auto_increment = newvalue
Rails: Check missing Foreign Key Indexes
c = ActiveRecord::Base.connection
c.tables.collect do |t|
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
un...
Posted by Luis Romero to Custom Exposure (2014-08-27 18:28)