Jan
17th

How to backup and import a MySQL InnoDB database

Files under Linux, MySQL | 1 Comment

Due to the way Innodb tables are structured, you cannot perform a hotback up of this database without using third party tools. Therefore you must take your database offline for a small period of time while you take the backup.

Backing up MySQL

MySQL backups are performed using the common mysqldump tool. This is a command line utility that ships with MySQL and you use at as follows:

% mysqldump --user=user --password=pass --opt DBNAME > dumpfile.sql

You may also need to specify the --host= parameter to force the hostname you are connecting to. This depends largely on how you’ve setup your user security. This will produce a text file with a series of INSERT/DROP/CREATE SQL statements that will recreate the database.

(more…)

Jan
17th

How to clear shell command path cache?

Files under Linux | 3 Comments

All UNIX shells cache the command paths based on the contents of PATH enviromental variable. This can cause a problem if a cached path no longer exists. For example, you have a command “foo” installed in /usr/bin and /usr/local/bin. Your PATH variable is set to “/usr/local/bin:/usr/bin“.

When you run “foo“, it is searched under each directory listed in PATH and the results are cached. In this case, the path “/usr/local/bin/foo” will be cached for “foo“.

Now suppose you delete the command file “/usr/local/bin/foo“. You still have another copy in “/usr/bin/foo“. However, the next time you type “foo“, the shell will return an error such as this:

 -bash: /usr/local/bin/foo: No such file or directory

To clear the cached path of foo command, you can run

 $ PATH=$PATH

This basically resets the PATH variable, thereby clearing the cache. * For bash shell, you might be able to do the same thing using

 $ hash -r

Although, the previous method should also work for bash.

Jan
17th

How to find out what application is using your port

In Linux:

The linux fuser command has a special option for port conflicts.

Use fuser -n tcp <port id> for tcp ports to see which process is using the port.

For example to see which application is already using port 80 use:

$ fuser -n tcp 80

The netstat command can also be used to determine what process is using a port.

Use netstat -nlp and you should see PID and names of programs along with the port they are using (note you can only see the PID of process you own, unless running as root)

$ netstat --nlp

In Windows:

On Windows 2003 the options are as follows: netstat -a -b -o -n

  • -a: gets listening processes (similar to -l on linux)
  • -b: displays the executable name that started using the port (similar to -p on linux)
  • -o: displays the process id (PID) that owns the connection
  • -n: (optional) gives the addresses numerically (same as -n on linux)