Monthly Archives: February 2018

How to Import and export databases in mysql using terminal

mysql-database

Today I will be detailing about how to export/import large database file in mysql through terminal.

Export From a Database
To export a database from mysql trough terminal.

1- open console.
2- issue below command

mysqldump -u <username> -p <application_db>  >  <appdb>.sql

e.g. mysqldump -uroot -p application_database  >  application.sql


Import To Database

There are two ways to do the same.

First Method

Assuming you’re on a Linux or Windows console:

1- Open console
2- issue below command

mysql -u <username> -p <database_name> < <filepath/filename.sql>

e.g  mysql -uroot -p application_db   < /abhishek/application_database.sql

It will prompt for password and do the job, You may see an idle screen while import is being done there.
There will be no status displayed untill it reaches to end of script.

You may also provide the password directly in the same line as below.

mysql -u <username> -p<dbuserpassword> <database_name> < <filepath/filename.sql>

e.g  mysql -uroot -pabhishek  application_db   < /abhishek/application_database.sql

It will work exactly similar to above provided it will not ask for password, as we have already provided in command.

Second Method

1- Open console
2- start mysql interactive mode as below

mysql -u<database_username> -p

e.g. mysql -uroot -p

It will prompt for password, provide password of mysql user and proceed to step 3.

3- select database in which file will be imported. (Assuming database name is application_db)

use <database_name>

use application_db

4- issue below command to import. (assuming here test.sql is our file to import)

source  <path_to_sqlfile_test.sql>

e.g. source  /path_to_sqlfile/test.sql

It will show the status too, while import script is running there. In this second approach seems more better than the first one as user is aware of its current progress of import.

git pull vs git fetch

git pull — Incorporates changes from a remote repository into the current branch. In its default mode,

In the simple terms, git pull does a git fetch followed by a git merge.

More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With –rebase, it runs git rebase instead of git merge.

You can do a git fetch at any time to update your remote-tracking branches under refs/remotes/<remote>/.

A git fetch, operation never changes any of your own local branches under refs/heads, and is safe to do without changing your working copy.

A git pull is what you would do to bring a local branch up-to-date with its remote version, while also updating your other remote-tracking branches.

 

SSH vs PuTTY vs VNC

As many of us have heard about the terms like SSH, Putty, VNC . Let’s see how to they differ with each other.

SSH is a protocol for encrypted connections between computers(For making connections, ssh client needs to be installed on local computer, and ssh server needs to be installed at remote computer) . Its simple to use, SCP command is also based on ssh, with help of ssh one can perform task over remote computer.

PuTTY is a free implementation of SSH and Telnet for Windows and Unix platforms, along with an xterm terminal emulator.

PuTTY is a GUI terminal emulator (able to run shells, which in turn run commands), while the usual SSH application is a shell (not a terminal emulator). PuTTY has been ported to Unix (and Unix-like) systems as pterm.

As a best practice, keys are recommends over passwords. PuTTY is the terminal client but you can get a couple of other tools from the same author. PSFTP and PSCP offer secure file transfers. These tools are as easy to use as PuTTY and work pretty much the same way.

VNC exports a whole session, desktop and all, while ssh will run a single program and show its windows on your workstation.

The VNC server exports a session that survives even when you disconnect your screen, and you can reconnect to it later with all the windows open etc. This is not possible with an ssh X tunnel, since when your X server dies, the windows go away.