MySQL Dump/Restore Stored Procedures and Triggers

mysqldump will backup by default all the triggers but NOT the stored procedures/functions. There are 2 mysqldump parameters that control this behavior:

—routines – FALSE by default
—triggers – TRUE by default

This means that if you want to include in an existing backup script also the triggers and stored procedures you only need to add the —routines command line parameter:

mysqldump <other mysqldump options> --routines outputfile.sql

Let’s assume we want to backup ONLY the stored procedures and triggers and not the mysql tables and data (this can be useful to import these in another db/server that has already the data but not the stored procedures and/or triggers), then we should run something like:

mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql

and this will save only the procedures/functions/triggers of the . If you need to import them to another db/server you will have to run something like:

mysql <database> < outputfile.sql

Access MySQL Without Password

For MySQL you can specify your user and password in local config file (.my.cnf). This file should be in your home directory (i.e. ~/.my.cnf).

.my.cnf:

[mysql]
user=user
password=password

How do you gunzip a file and keep the .gz file?

You’re looking for:

gzcat x.txt.gz >x.txt

The gzcat command is equivalent to gunzip -c which simply writes the output stream to stdout. This will leave the compressed file untouched. So you can also use:

gunzip -c x.txt.gz >x.txt

Note that on some systems gzcat is also known as zcat so run like this instead:

zcat x.txt.gz >x.txt

How to gzip and keep original file on Unix or Linux command line

I would like to compress a log file using gzip Unix command line utility, and I would also like to keep the original file. However, when I use the gzip my-app.log command, results in modifying my log file and renaming it my-app.log.gz. How do I force the gzip command to keep original file while maintaining the original file on Linux or Unix-like system?

The gzip program compresses and decompresses files on Unix like system. You need to pass the -c or --stdout, or --to-stdout option to the gzip command. This option specifies that output will go to the standard output stream, leaving original files intact.

Continue reading

Routing to allow SSH over a specific interface

Sometime when you have two network interfaces (say eth0 and eth1) on the client and for some reason there is a need to SSH to the server over a specific a specific interface. By default the primary interface will be used. To use eth1 we just need to add a route:

route add -net 10.75.0.0 netmask 255.255.255.0 gw 192.168.0.1 eth1

The route is removed upon reboot. Use -p to permanently add the route to the table. To delete the route:

route del -net 10.75.0.0 netmask 255.255.255.0 gw 192.168.0.1 eth1

 

Develop a modular application – Loading classes using ClassLoader

In Java, all the classes are loaded using several ClassLoader. In this article, we’ll develop a loader for our modules and watch the problems that arrive when working with custom ClassLoaders.

Normally, Java use the system ClassLoader to load all the classes of our application. So it contains all the classes of our application and all the classes our application needs to work. But the problem is that we cannot add our modules jar files into classpath because the application doesn’t know the modules jar files names.

Continue reading

Simplify Your Life With an SSH Config File

If you’re anything like me, you probably log in and out of a half dozen remote servers (or these days, local virtual machines) on a daily basis. And if you’re even more like me, you have trouble remembering all of the various usernames, remote addresses and command line options for things like specifying a non-standard connection port or forwarding local ports to the remote machine.

Continue reading

How to automatically save screenshots to Google Drive on macOS

Saving screenshots to Drive automatically

  1. Create a new folder called “Screenshots” in your Google Drive.
  2. Open Terminal.
  3. Run the following commands:
defaults write com.apple.screencapture location ~/Google\ Drive/Screenshots/
killall SystemUIServer

Now screenshots will be saved to the Screenshots folder in your Google Drive, not the desktop.