Sign up with your email address to be the first to know about new products, VIP offers, blog features & more.

View MySQL and MongoDb Queries – Live on Terminal

Intro

Frequently, during the development and debugging processes, the need for live auditing database’s CRUD operations, arises. So i decided to create this post to make it easy for us to remember, copy and paste. This is a nice option because you can decide not to enable general by not adding the arguments above. An alternative would be setting that information on mysql.conf on on mongo.config, but we may forget them there, and they can slow down our local queries or create a huge log file. This is my preferred way to enable general log and inspect them.

MySQL

Enabling logging during service startup

mkdir -p /usr/local/var/log/mysqld/ && touch /usr/local/var/log/mysqld/general.log

mysqld --general_log=1 --general_log_file="/usr/local/var/log/mysqld/general.log"

Live watching queries

tail -f /usr/local/var/log/mysqld/general.log | grep "INSERT\|SELECT\|UPDATE\|DELETE"

MongoDB

Enabling logging during startup

mkdir -p /usr/local/var/log/mongod/ && touch /usr/local/var/log/mongod/general.log
  
mongod --profile=2 --slowms=1 --logpath "/usr/local/var/log/mongod/general.log" --logappend --dbpath="/Users/fernandorodrigues/Documents/Axia AI/axia_mongo_db_data"

Live watching queries

tail -f /usr/local/var/log/mongod/general.log | grep "insertOne\|insertMany\|find\|updateOne\|updateMany\|replaceOne\|deleteOne\|deleteMany"

No Comments Yet.

What do you think?

Your email address will not be published. Required fields are marked *