How to migrate a MySQL database from one Linux server to another using the command the line

How to move/migrate a MySQL database from one Linux server to another via the command line using “mysqldump” to export the database , “scp” (secure copy) to transfer it, and “mysql” to import it.

In this example, we’ll migrate/move a theoretical SQL database named twatdb from it’s current location on example.com over to the twat.ca server.

1. Export the database from the old server using “mysqldump”

For our example, let’s say our database is named “junglist”. Before transferring the database file to the new VPS, we first need to create a database dump on the original server using mysqldump:

mysqldump -u root -p –opt [database name] > [database file].sql

2. Transfer the .sql database file to the new server

While there’s many different ways we could move our .sql file over to the new server (SFTP, rsync, etc.) we’re going to use “scp” (secure copy) in this example.

Syntax: scp [database name].sql [username]@[servername]:path/to/database/

Using scp, we’ll put the file in our home folder on the new server:

3. Import the database on the new server

Log in to your new server via SSH and import using mysql:

mysql -u root -p [database name] < [database file].sql

How to check your connection speed with Speedtest.net from Ubuntu/Debian command line

How to check your internet connection speed using the “speedtest-cli” Python application for Ubuntu & Debian and optionally share your results.

1. Install speedtest-cli application

Note: You can optionally skip the “sudo” prefixes on the commands below by switching to root using the sudo su command.

First, make sure your list of repository packages is up to date:

Next, install the Python package manager (pip):

Now install the speed-cli application using Python package manager (pip):

And if you ever want to upgrade the application, you can use:

2. Test your connection speed using speedtest-cli application

To check your internet connection speed, run the speedtest-cli application:

Alternatively, if you want to be able to share your results:

Run the speedtest-cli application using the optional share argument:

Paste the address above into a browser to see the result. Example:

6017542333.png Speedtest.net result

For additional information:

  • Speedtest.net website (the original web-based version)
  • Run speedtest-cli using the optional help argument:

How to change your SSH port from the default of 22 on Ubuntu 14.04

A little security through obscurity by changing the SSH (Secure Shell) port on your server from the default of 22.

This page explains how to change the SSH (Secure Shell) port from the default of 22. Using port 22 doesn’t make your system insecure, nor will changing the port from 22 provide any significant variance in security. However, changing the default SSH port will help stop many automated attacks by making it a bit harder to guess which port the secure shell (SSH) is accessible from. In other words, security though obscurity.

1. Connect to your server via SSH

Connect to your server using an SSH client such as PuTTY (for Windows) or OpenSSH for Mac/Linux

2. Edit the /etc/ssh/sshd_config file using root permissions

To edit the file using ‘nano’:

3. Locate the line that looks like one of the following:

4. Edit the line to remove the # and change 22 to the SSH port number you’d like to use.

For example:

Save and exit. If using nano, press Control-X, then Y, then hit Enter.

5. Restart the sshd service on your server

Type the following command:

You should see something like this:

6. Ensure that you’re able to connect using the new port.

Before disconnecting, we recommend verifying that you’re able to connect using the new port. If you can’t, try repeating the above steps with another port or switch back to 22.

Use your your preferred SSH client (see Step #1) or type the following from your existing shell, replacing 59522 with the port number chosen in Step #4:

For more information:

Copy files to, from, or between different hosts using Secure Copy (scp)

Secure Copy (scp) copies files between hosts on a network. It uses SSH (Secure Shell) for data transfer, and uses the same authentication and provides the same security as SSH.

Examples:

Copy the file “foobar.txt” from a remote host to the local host:

Copy the file “foobar.txt” from the local host to a remote host:

Copy the directory “foo” from the local host to a remote host’s directory “bar”:

Copy the file “foobar.txt” from remote host “rh1.edu” to remote host “rh2.edu”:

Copying the files “foo.txt” & “bar.txt” from the local host to your home directory on the remote host:

See more scp examples:

How to check the uptime of a Linux server

See how long your server’s been up without a reboot or crash.

Just type ‘uptime’ and you’re done:

Output:
This shows that it’s currently 2:36am, the server has been up for 28 days, 19 hours and 35 minutes, and there is one user connected.  The load average displays the average CPU load over the past last one, five, and fifteen minutes.

Install LambdaMOO 1.8.1 server with LambdaCore database on Ubuntu 12

MOO = MUD Object-Oriented. This will show you how to download and compile LambdaMOO 1.8.1 server and get it running as a background process using the LambdaCore database.

 

Download the LambdaMOO server into your home folder using ‘wget’:

Output:

Extract the LambdaMOO .tar.gz archive:

Output:

Change directory & run the configure script:

Output:

You may have to install yacc before the next step:

Output:

Compile the server:

Output:
I’m not sure what the errors are all about but it seems to run fine regardless!

Download the LambdaCore database:

Output:

Extract the LamdaCore database:

That’s it, now you should be able to start up the MOO:

The format is: ./moo <input-db-file> <output-db-file> <port> &
The & is used to run it in the background so you don’t need to keep the window open.

Output:

To test it, just telnet to the port you specified above:

Output:

LINKS:

Download LambdaMOO-latest.tar.gz (server)
Download LambdaCore (database)

And be sure to visit Lisdude’s MOO Resources page:

Lisdude’s MOO Resources

Extract a .tar.gz archive to a specific location in Ubuntu 12.04

How to extract a .tar.gz file to a specific folder and vice versa (create a .tar.gz file from a folder) using the ‘tar’ command from Ubuntu 12.04 command-line terminal.

To extract .tar.gz:

Usage: tar -zxvf <filename>
Usage: tar -zxvf <filename> -C <folder>

  • -z : filter the archive through gzip
  • -x : extract files from an archive
  • -v : verbosely list files processed
  • -f filename : use archive file or device ARCHIVE

Examples:

Or, to do the opposite (create .tar.gz archive from a folder):

  • -z : filter the archive through gzip
  • -c : create a new archive
  • -v : verbosely list files processed
  • -f  filename : use archive file or device ARCHIVE

To exclude specific filetypes from either of the above, you can use –exclude … the following example excludes all .mp3 and .tar.gz files:

Example to create a .tar (non .gz) file  in the current folder named test.tar, archiving the folder /home/jamesc/test

Tar usage (output of “tar –help”)

 

Reload config file for Icecast radio streaming server without dropping listeners

How to reload the /etc/icecast2/icecast.xml configuration file for Icecast radio streaming server without dropping your listeners, DJs, or affecting your stream.

Type:

or, find the PID for your Icecast process using “ps aux” (example: 1234) and type:

 

While kill and killall do normally terminate tasks, in this instance they’re being used to send a “hangup signal” (-HUP) which forces Icecast to refesh the configuration file (usually /etc/icecast2/icecast.xml) without dropping any of the client connections. Pretty hard to understate the usefulness of this, especially on a production server.

How to switch to another user using sudo in Ubuntu 12.04 shell

How to switch to another user from the Ubuntu 12.04 command-line shell without the password of the target user. Must have sudo permissions.

Usage: sudo -u <username> <shell>

Assuming your account has root/sudo permissions:

You may have to type in your password (not the password of the account you’re switching to.)

Just type “exit” to get back to your original session: