Skip to content

Instantly share code, notes, and snippets.

@dungmanh88
dungmanh88 / keybase.md
Last active September 12, 2019 02:00
keybase

Keybase proof

I hereby claim:

  • I am dungmanh88 on github.
  • I am panther88 (https://keybase.io/panther88) on keybase.
  • I have a public key ASA6l5ZmpGdbJSf5lJkaIVs5Wy28nRJ5IMiOT8zkV3VLYwo

To claim this, I am signing this object:

@dungmanh88
dungmanh88 / keybase.md
Created September 12, 2019 01:52
keybase description

Keybase proof

I hereby claim:

  • I am dungmanh88 on github.
  • I am panther88 (https://keybase.io/panther88 ) on keybase.
  • I have a public key ASB2xjApCcXQYwcW8BJt1c6s7lX4nEAUSZXukDEHyYWJuwo

To claim this, I am signing this object:

@dungmanh88
dungmanh88 / Count collection in MongoDB
Created December 16, 2016 09:05
Count collection in MongoDB
vi mongodb_collection_size.js
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(stats[c]['ns'] + ":" + stats[c]['count'] + ":" + stats[c]['size'] + "(" + stats[c]['storageSize'] + ")"); }
mongo --port 27017 -u myUserAdmin -p abc123 --authenticationDatabase admin <DB> mongodb_collection_size.js
@dungmanh88
dungmanh88 / Profiling mysql query
Created November 15, 2016 07:53
Profiling mysql query
mysql> set profiling=1;
mysql> // command
mysql> show profiles;
mysql> show profile for query 1;
mysql> set @query_id=1;
mysql> SELECT STATE, SUM(DURATION) AS Total_R, ROUND(100 * SUM(DURATION) / (SELECT SUM(DURATION) FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = @query_id), 2) AS Pct_R, COUNT(*) AS Calls, SUM(DURATION) / COUNT(*) AS "R/Call" FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = @query_id GROUP BY STATE ORDER BY Total_R DESC;
@dungmanh88
dungmanh88 / Partitioning and Formatting a new disk
Created October 21, 2016 08:34
Partitioning and Formatting a new disk
parted /dev/sdb
(parted) mklabel msdos
(parted) mkpart primary ext4 0% 100%
(parted) print
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 107GB 107GB primary ext4
(parted) quit
@dungmanh88
dungmanh88 / Do all tables have primary key ?
Created October 19, 2016 08:09
Do all tables have primary key ?
select t.table_schema, t.table_name
from information_schema.tables t
left join information_schema.statistics s
on t.table_schema=s.table_schema and t.table_name=s.table_name and s.non_unique=0
where s.table_name is null and t.table_schema not in ('mysql', 'information_schema','performance_schema');
@dungmanh88
dungmanh88 / Create a mysql account with basic permission
Created October 18, 2016 07:42
Create a mysql account with basic permission
mysql> grant index, create temporary tables, create view, show view, create routine, alter routine, trigger, delete, insert, select, update, execute on `test`.* to 'user'@'host' identified by 'auth_string';
mysql> flush privileges;
@dungmanh88
dungmanh88 / Schedule to stop mongo sharding balancer
Created October 6, 2016 02:35
Schedule to stop mongo sharding balancer
use config
db.settings.update( { _id : "balancer" }, { $set : { activeWindow : { start : "06:00", stop : "23:59" } } }, true )
@dungmanh88
dungmanh88 / Read binlog using mysqlbinlog
Created October 5, 2016 07:19
Read binlog using mysqlbinlog
mysqlbinlog -vv --base64-output=decode-rows mysql-bin.xxxxxx > /tmp/binlog
@dungmanh88
dungmanh88 / Percona toolkit example
Created October 4, 2016 16:41
Percona toolkit example
pt-variable-advisor localhost --user=root --ask-pass
Just compare in mysqld section
pt-config-diff /etc/my.cnf.d/server.cnf h=localhost --user=root --ask-pass
pt-config-diff /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server1.cnf
pt-summary
pt-mysql-summary --user=root --ask-pass