Powered by Blogger.

How to Backup and Restore (Export and Import) MySQL Databases Tutorial

Tuesday, December 8, 2009

How to Backup and Restore (Export and Import) MySQL Databases Tutorial

phpMyAdmin can be used to export or backup MySQL databases easily. However, if the database size is very big, it probably won't be a good idea. phpMyAdmin allows users to save database dump as file or display on screen, which involves exporting SQL statements from the server, and transmitting the data across slower network connection or Internet to user's computer. This process slow the exporting process, increase database locking time and thus MySQL unavailability, slow the server and may simply crash the Apache HTTPD server if too many incoming web connections hogging the system's resources.

The better way to backup and export MySQL database is by doing the task locally on the server, so that the tables' data can be instantly dumped on the local disk without delay. Thus export speed will be faster and reduce the time MySQL database or table is locked for accessing. This tutorial is the guide on how to backup (export) and restore (import) MySQL database(s) on the database server itself by using the mysqldump and mysql utilities. There are basically two methods to backup MySQL, one is by copying all table files (*.frm, *.MYD, and *.MYI files) or by using mysqlhotcopy utility, but it only works for MyISAM tables. Below tutorial will concentrate on mysqldump which works for both MyISAM and InnoDB tables.

How to Export or Backup or Dump A MySQL Database

To export a MySQL database into a dump file, simply type the following command syntax in the shell. You can use Telnet or SSH to remotely login to the machine if you don't have access to the physical box.

mysqldump -u username -ppassword database_name > dump.sql

Replace username with a valid MySQL user ID, password with the valid password for the user (IMPORTANT: no space after -p and the password, else mysqldump will prompt you for password yet will treat the password as database name, so the backup will fail) and database_name with the actual name of the database you want to export. Finally, you can put whatever name you like for the output SQL dump file, here been dump.sql.

The while data, tables, structures and database of database_name will be backed up into a SQL text file named dump.sql with the above command.

How to Export A MySQL Database Structures Only

If you no longer need the data inside the database's tables (unlikely), simply add –no-data switch to export only the tables' structures. For example, the syntax is:

mysqldump -u username -ppassword –no-data database_name > dump.sql

How to Backup Only Data of a MySQL Database

If you only want the data to be backed up, use –no-create-info option. With this setting, the dump will not re-create the database, tables, fields, and other structures when importing. Use this only if you pretty sure that you have a duplicate databases with same structure, where you only need to refresh the data.

mysqldump -u username -ppassword –no-create-info database_name >dump.sql

How to Dump Several MySQL Databases into Text File

–databases option allows you to specify more than 1 database. Example syntax:

mysqldump -u username -ppassword –databases db_name1 [db_name2 ...] >dump.sql

How to Dump All Databases in MySQL Server

To dump all databases, use the –all-databases option, and no databases' name need to be specified anymore.

mysqldump -u username -ppassword –all-databases > dump.sql

How to Online Backup InnoDB Tables

Backup the database inevitable cause MySQL server unavailable to applications because when exporting, all tables acquired a global read lock using FLUSH TABLES WITH READ LOCK at the beginning of the dump until finish. So although READ statements can proceed, all INSERT, UPDATE and DELETE statements will have to queue due to locked tables, as if MySQL is down or stalled. If you're using InnoDB, –single-transaction is the way to minimize this locking time duration to almost non-existent as if performing an online backup. It works by reading the binary log coordinates as soon as the lock has been acquired, and lock is then immediately released.

Syntax:

mysqldump -u username -ppassword –all-databases –single-transaction > dump.sql

How to Restore and Import MySQL Database

You can restore from phpMyAdmin, using Import tab. For faster way, upload the dump file to the MySQL server, and use the following command to import the databases back into the MySQL server.

mysql -u username -ppassword database_name < dump.sql

The import and export of MySQL database not only is important to recover the data when disaster strikes, but also provides an easy way to migrate or move to another server, such as when switching web hosting providers. However, do note that one common problem – character set encoding. Newer release of mysqldump uses UTF8 as its default charset if nothing is specified, while older versions (older than 4.1 typically) use Latin1 as default characterset. If you database charset is Latin1 and dump in UTF8 collation, the data may ends up become simply rubbish, garbled, or unreadable (frequently happen with Wordpress blog). If this case, use –default-character-set=charset_name option to specify the character set or convert the database to UTF8.

Bootable ubuntu flash stick

Thursday, October 29, 2009

How-to: Installing Ubuntu Linux on a usb pendrive

This tutorial will show how-to install Ubuntu on a usb stick. Even though this tutorial uses Ubuntu as its base distribution, you could virtually use any type of Linux liveCD distribution.
Being able to run Linux out of a usb bar is a great way to enjoy the live CD experience (being able to use Linux on any computer you might get by) and the big advantage of being easier to carry around than a CD.

1. Requirements

In order to reproduce this tutorial, you will need a few items such as:
  • a ubuntu liveCD
  • a usb bar of at least 1G
  • a running Linux operating system
Now that you have all this, it is time to prepare you USB bar do host the Ubuntu liveCD files.

2. Setting up the USB disk

2.1. Finding the device

In the first place, you need to plug your usb drive and check under which device it is associated. To find out the device, run:
$ sudo fdisk -l
On my system, the device appears as being /dev/sdb, I will therefore use /dev/sdb as a reference for this tutorial, please replace it accordingly to your system (might be sda, sdc ...).
Once you found your device, you are going to create the partitions.
Using the wrong device name might destroy your system partition, please double check

2.2. Making the partitions

Make sure every of your already mounted partition are unmounted:

$sudo umount /dev/sdb1
and then launch fdisk, a tool to edit partition under linux:
sudo fdisk /dev/sdb
We are going delete all the partition and then create 2 new partition: one fat partition of 750M which will host the files from the live CD iso, and the rest on another partition.
At fdisk prompt type d x where x is the partition number (you can simply type d if you only have one partition), then:
  • n to create a new partition
  • p to make it primary
  • 1 so it is the first primary partition
  • Accept the default or type 1 to start from the first cylinder
  • +750M to make it 750 Meg big
  • a to toggle the partition active for boot
  • 1 to choose the 1 partition
  • t to change the partition type
  • 6 to set it to FAT16
Now we have out first partition set up, let's create the second one:
  • n to create yet again a new partition
  • p to make it primary
  • 2 to be the second partition
  • Accept the default by typing Enter
  • Accept the default to make your partition as big as possible
  • Finally, type w to write the change to your usb pendrive
Partitions are now created, let's format them.

2.3. Formatting the partitions

The first partition is going to be formated as a FAT filesystem of size 16 and we are going to attribute it the label "liveusb".
$ sudo mkfs.vfat -F 16 -n liveusb /dev/sdb1
The second partition is going to be of type ext2 with a blocksize of 4096 bytes and the label casper-rw. Mind that it has to be labeled as casper-rw otherwise the tutorial won't work!.
$ sudo mkfs.ext2 -b 4096 -L casper-rw /dev/sdb2
At this stage, our usb pendrive is ready to host the liveCD image. Now, let's copy the files to the usb bar.

3. Installing Ubuntu on the USB stick

3.1. Mounting Ubuntu liveCd image

In the first place we need to mount our ubuntu iso. Depending if you have the .iso file or the CD, there is 2 different ways of mounting it.

3.1.1. Mounting from the CD

People using Ubuntu or any other user-friendly distro, might just have to insert the cd and it will be mounted automatically. If this is not the case:
$ sudo mount /media/cdrom
should mount it.

3.1.2. Mounting from an .iso image file

We will need to create a temporary directory, let say /tmp/ubuntu-livecd and then mount our iso (I will be using a feisty fawn iso).
$ mkdir /tmp/ubuntu-livecd
$ sudo mount -o loop /path/to/feisty-desktop-i386.iso /tmp/ubuntu-livecd
Once the cd image is ready, it is time to mount the newly created usb bar partitions:

3.2. Mounting the usb bar partitions

Same here, you might be able to get both your partition by simply replugging the usb pendrive, partition might appears as: /media/liveusb and /media/casper-rw. If this is not the case, then you will need to mount them manually:
$ mkdir /tmp/liveusb
$ sudo mount /dev/sdb1 /tmp/liveusb
All the partitions we need are now mounted, let's copy the files.

3.3. Copying the files to the usb bar

Let positionned yourself on the CD image directory (in my case: /tmp/ubuntu-livecd , but it might be /media/cdrom , and copy at the root of your usb first partition:
  • the directories: 'casper', 'disctree', 'dists', 'install', 'pics', 'pool', 'preseed', '.disk'
  • The content of directory 'isolinux'
  • and files 'md5sum.txt', 'README.diskdefines', 'ubuntu.ico'
  • as well as files: 'casper/vmlinuz', 'casper/initrd.gz' and 'install/mt86plus'
$ cd /tmp/ubuntu-livecd
$ sudo cp -rf casper disctree dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines ubuntu.ico casper/vmlinuz casper/initrd.gz install/mt86plus /tmp/liveusb/
It might complain about symbolic links not being able to create, you can ignore this.
Now let's go to the first partition of your usb disk and rename isolinux.cfg to syslinux.cfg:
$ cd /tmp/liveusb
$ sudo mv isolinux.cfg syslinux.cfg
change /tmp/liveusb according to your settings
Edit syslinux.cfg so it looks like:
DEFAULT persistent
GFXBOOT bootlogo
GFXBOOT-BACKGROUND 0xB6875A
APPEND  file=preseed/ubuntu.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL persistent
   menu label ^Start Ubuntu in persistent mode
  kernel vmlinuz
  append  file=preseed/ubuntu.seed boot=casper persistent initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL live
  menu label ^Start or install Ubuntu
   kernel vmlinuz
  append  file=preseed/ubuntu.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL xforcevesa
  menu label Start Ubuntu in safe ^graphics mode
  kernel vmlinuz
   append  file=preseed/ubuntu.seed boot=casper xforcevesa initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL check
  menu label ^Check CD for defects
  kernel vmlinuz
  append  boot=casper integrity-check initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
 LABEL memtest
  menu label ^Memory test
  kernel mt86plus
  append -
LABEL hd
  menu label ^Boot from first hard disk
  localboot 0x80
  append -
DISPLAY isolinux.txt
TIMEOUT 300
PROMPT 1
 F1 f1.txt
F2 f2.txt
F3 f3.txt
F4 f4.txt
F5 f5.txt
F6 f6.txt
F7 f7.txt
F8 f8.txt
F9 f9.txt
F0 f10.txt
Woof, finally we have our usb disk almost usuable. We have a last thing to do: make the usb bootable.

3.4. Making the usb bar bootable.

in order to make our usb disk bootable, we need to install syslinux and mtools:
$ sudo apt-get install syslinux mtools
And finally unmount /dev/sdb1 and make it bootable:
$ cd
$ sudo umount /tmp/liveusb
$ sudo syslinux -f /dev/sdb1
Here we are :D , reboot, set your BIOS to boot from the usb bar and enjoy Ubuntu linux from a pendrive

4. Troubleshooting

If you are having trouble booting on the usb bar, this might be due to your MBR being corrupted. In order to fix it up, you can use lilo (I installed lilo on my box only for thid purpose).
$ lilo -M /dev/sdb
will fix the MBR on device /dev/sdb

recover GRUB

GRUB recovery after installing Windows XP

Posted by: ranacse05 on: January 12, 2008

If any one use dual boot system then after installing windows again we lost GRUB loader. It can recover in various method. Here i discuss GRUB recovery using Live cd. For this we have to boot our system by Live cd.

Follow the step to recover grub bootloader:
1. Boot with Ubuntu Live CD
2. Open gnome-terminal
Give the commands:
3. sudo grub
then it shows grub> like this
grub>find /boot/grub/stage1
it'll give a output like this (hd0,7)  7 is here for example, itĺl be number of ur partition.
grub>root (hd0,7)
grub>setup (hd0)
grub>quit

Then reboot your machine. I think your boot loader should recovered.
there is another way.
1. Boot with Fedora CD 1.
2. write
linux rescue
it'll open a shell
write
grub

then write previous grub command

Spacial thanks to Suzan bhai & Asad

Note: For hda1,sda1 it'll be (hd0,0),hda2,sda2 it'll be (hd0,1),hdb1,sdb1 it'll be (hd1,0)

Bootable ubuntu flash stick

http://www.debuntu.org/how-to-install-ubuntu-linux-on-usb-bar

Fomat a Flash drive in Ubuntu

Thursday, September 10, 2009

1. use "df"
    displays file systems available
    find out the volume label of the flash drive

2. unmount the volume before format

3. to format for ext3: "mkfs /dev/sdb1"
    to format for fat: "mkfs -t vfat /dev/sdb1"

4. mount the volume back

English Sinhala Dictionary for Firefox

Thursday, September 3, 2009

In Firefox: tools - > add-ons

search for "EnSiTip" and install it

restart Firefox and place the mouse pointer to the word that you want to find the Sinhala meaning

Sinhala unicode in ubuntu 9.04

1. Enable universe repository

2. apt-get install ttf-sinhala-lklug scim scim-gtk2-immodule im-switch scim-m17n m17n-db m17n-contrib language-pack-si-base
 3. rm -f ~/.xinput.d/* ; im-switch -z all_ALL -s scim-immodule

Insert in-line images in gmail

Wednesday, September 2, 2009

1. Enable the lab called 'Inserting images'
2. Then there will be a new button called 'insert image' in mail formatting tool bar
3. Click and insert the image

Start gDesklets automatically in every boot

1. system -> preferences -> startup applications



2. Click on the "Add" button



3. Enter the required details

Problem when installing gDesklets

Tuesday, September 1, 2009

I got this error when I tried the command "gdesklets" from terminal

bash: /usr/bin/gdesklets: /usr/bin/python2.5: bad interpreter: No such file or directory

by installing python 2.5 using following command we can fix the error

sudo apt-get install python2.5

gDesklets

sudo apt-get install gdesklets

Ubuntu: How to find the VGA card type

Thursday, July 23, 2009

# lspci | grep VGA


out put of my laptop:

01:00.0 VGA compatible controller: VIA Technologies, Inc. CN896/VN896/P4M900 [Chrome 9 HC] (rev 01)

How to install MySQL On Ubuntu

Friday, July 17, 2009

Installing MySQL on Ubuntu:

        To open the Terminal, go to Application > Accessories > Terminal

         

          Type the following command at terminal.

  •  $sudo apt-get install mysql-server

             To be able to connect to mysql from internet, remove the restriction on the below file.

  • Open the file by typing the following command at terminal prompt.

          $gksudo gedit /etc/mysql/my.cnf

  • Find the line bind-address = 127.0.0.1 and comment it out as shown below.
           

         #bind-address           = 127.0.0.1 

  • mysql comes with no root password. To set the root password, type:

        $mysqladmin -u root password your-new-password

          $sudo /etc/init.d/mysql restart


  • Install mysql query browser
         $sudo apt-get install mysql-query-browser

  • After installing, go to Applications > Programming > MySQL Query Browser to connect to mysql as shown below.

             
             Enter Server Hostname, Username and Password. Click on Connect and MySQL is now installed on Ubuntu.

           

Compiling your first C++ program with ubuntu

Compiling your first C++ program
If you want to run c++ program follow this procedure
g++ is the compiler that you must use.
you should use a .cpp file extension rather than a .c one
You need to create a file
sudo gedit first.cpp
add the following lines save and exit the file

Run your C++ Program using the following command
g++ first.cpp -o test
./test
Output should show as follows
Hello World!

Assign IPv6 address in Windows XP from command line

Monday, May 4, 2009

Command:
netsh interface ipv6 add address interface=<> address=<> type=<> validlifetime=<> preferredlifetime=<> store=<>

interface
: Interface name or index
address: IPv6 address to add
type: unicast or anycast
validlifetime: lifetime over which the address is valid (integer | infinite), Default is infinite
preferredlifetime: lifetime over which the address is preferred (integer | infinite), Default is infinite
store: (active: change only lasts until next boot | persistent: change is persistent(Default))

Example:
netsh interface ipv6 add address "LAN" 2001::4 type=unicast

here "LAN" is the name of interface, 2001::4 is the IPv6 address

Note:
- to get information about windows commands, try: command ?

IPv6 addressing examples

Friday, May 1, 2009

IPv6 address

Prefix length (bits)

Description

Notes

::

128

unspecified

cf. 0.0.0.0 in IPv4

::1

128

loopback address

cf. 127.0.0.1 in IPv4

::

96

embedded IPv4

These are IPv4 addresses rendered as 128-bit values (the top 96 bits are zero). Also called "IPv4 compatible IPv6 address".

::ffff:0000:0000

96

IPv4 mapped IPv6 address

The lower 32 bits are the IPv4 address. For hosts which do not support IPv6.

fe80::

10

link-local

Unroutable addresses used for local autoconfiguration.

fec0::

10

site-local

Addresses used only within one local network, unroutable outside it. Cf. RFC 1918 addresses such as used in NAT.

ff::

8

multicast

2000::

3

global unicast

All global unicast addresses are assigned from this pool (starting with hex digit 2 or 3).

Ubuntu IPv6 Config

Suppose we want to keep dhcp configuration for IPv4 and want to use a static IP for IPv6

1. Open '/etc/network/interfaces'

sudo gedit /etc/network/interfaces

2. Edit it

auto eth0
iface eth0 inet dhcp

iface eth0 inet6 static
address 2001::1
netmask 64

3. Restart networking

sudo /etc/init.d/networking restart

ping to IPv6 host

Thursday, April 30, 2009

Type the command as follows:

$ ping6 localhost
$ ping6 host.domain.com
$ ping6 IPv6-address
$ ping6 2001:4860:b002::68

The best way is to ping global website such as ipv6.google.com, enter:
$ ping6 ipv6.google.com

Sample output:

ping6 ipv6.google.com
PING ipv6.google.com(2001:4860:b002::68) 56 data bytes
64 bytes from 2001:4860:b002::68: icmp_seq=0 ttl=59 time=58.4 ms
64 bytes from 2001:4860:b002::68: icmp_seq=1 ttl=59 time=56.4 ms
64 bytes from 2001:4860:b002::68: icmp_seq=2 ttl=59 time=62.1 ms
64 bytes from 2001:4860:b002::68: icmp_seq=3 ttl=59 time=56.8 ms
64 bytes from 2001:4860:b002::68: icmp_seq=4 ttl=59 time=56.5 ms
64 bytes from 2001:4860:b002::68: icmp_seq=5 ttl=59 time=59.5 ms

--- ipv6.google.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5002ms
rtt min/avg/max/mdev = 56.443/58.329/62.150/2.045 ms, pipe 2

Read ping6 man page for more information:
$ man ping6

dvrelay installation

Sunday, April 26, 2009

1. Install Linux kernel source code by using apt-get or yum

% sudo apt-get install linux-source

It will install latest version of Linux source code. We need to use the two header files from this kernel tree.
Extract source tree

% cd /usr/src
% sudo tar jxvf linux-source-2.6.22.tar.gz2

Create symbolic link from /usr/include
% cd /usr/include
% sudo ln –s /usr/src/linux-source-2.6.22/drivers/ieee1394/dv1394.h
% sudo ln –s /usr/src/linux-source-2.6.22/drivers/ieee1394/ieee1394-ioctl.h

2. Install libraw1394
Download libraw1394 from http://sourceforge.net/projects/libraw1394
Extract package, compile and install

% tar zxvf libraw1394-1.2.0.tar.gz
% ./configure
% make
% sudo make install
% sudo make dev

NOTE) If you have an error during "./configure", please run "sudo apt-get install build-essential" to prepare
development environment.

3. Install dvrelay

Download dvrelay from http://www.interlab.ait.ac.th/dvrelay/dvrelay0.1f.tar.gz
Extract package, compile and install

% tar zxvf dvrelay0.1f.tar.gz
% ./configure
% make
% sudo make install

You can confirm that dvrelay is installed at /usr/local/bin/dvrelay

How To Install OpenOffice.org 3.0.0 On Ubuntu 8.04

Sunday, April 19, 2009

1. Download the package
http://openoffice.bouncer.osuosl.org/?product=OpenOffice.org&os=linuxinteldeb&lang=en-US&version=3.0.1

2. Extract
sudo tar -zxvf OOo_3.0.1_LinuxIntel_install_en-US_deb.tar.gz

3. cd OOO300_m15_native_packed-1_en-US.9379/DEBS/

4. sudo dpkg -i *.deb

Install Times New Roman in Ubuntu

sudo apt-get install msttcorefonts
fonts can be found in /usr/share/fonts

VLC media player for Ubuntu

Saturday, April 18, 2009

Ubuntu Intrepid Ibex 8.10,
Ubuntu Hardy Heron LTS 8.04

Open Synaptic (System -> Administration -> Synaptic Package Manager). In Settings -> Repositories, make sure you have a "multiverse" repository activated.

Search for vlc and install it. You should also install vlc-plugin-esd, mozilla-plugin-vlc (and libdvdcss2).

Command line way

You need to check that a "multiverse" mirror is listed in your /etc/apt/sources.list.

% sudo apt-get update
% sudo apt-get install vlc vlc-plugin-esd mozilla-plugin-vlc

Listen live radio in Ubuntu

Thursday, April 16, 2009

Install required applications:

1. Applications -> Add/Remove
2. Select "Sound & Video" category from the left panel
3. Select show "All available applications"
4. Select the following applications
GStreamer extra plugins
GStreamer ffmpeg video plugin
GStreamer plugins for mms, wavpack, quicktime, musepack
5. Click "Apply changes"

Listen to internet radio

1. Applications -> Sound & Video -> Rhythmbox music player
2. Right click on the "Radio" category in the left panel and select "New internet radio station"
3. Enter URL and click on "Add"

How to set up network printer in Ubuntu

OS: Ubuntu 8.04

1. System -> Administration -> Printing
2. Click on the "New Printer" button
3. Select printer from the list and click Forward
4. Tick on the "Select printer from database" and select the printer make, click Forward
5. Select the model and driver, click Forward
6. Enter details, click Apply

How to view .chm files in Ubuntu

OS: Ubuntu 8.04

1. install xchm
sudo apt-get install xchm

Ubuntu Wing IDE Installation

Wednesday, April 15, 2009

OS: Ubuntu 8.04 (Hardy Heron)
Wing IDE version: wingide-101-3.1_3.1.8-1

1. Download WingIDE 101 for ubuntu/ debian
http://wingware.com/downloads/wingide-101

2. install enscipt
sudo apt-get install enscript

3. install wing IDE
sudo dpkg -i wingide-101-3.1_3.1.8-1_i386.deb

Ubuntu Python2.6 Installation

Monday, April 13, 2009

OS: Ubuntu 8.04 (Hardy Heron)
Python Version: 2.6.1

1. Install prerequisites
sudo aptitude install build-essential libncursesw5-dev libreadline5-dev
libssl-dev libgdbm-dev libbz2-dev libc6-dev libsqlite3-dev libdb-dev tk-dev

2. Download python 2.6
http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tar.bz2

3. Uncompress it
tar -jxvf Python-2.6.1.tar.bz2

4. Change directory to python extracted python directory
cd Python-2.6.1

5. create a directory to install python2.6
here i created a directory in /etc folder
sudo mkdir /etc/python2.6

6. Configure python to install to that directory
./configure --prefix==/etc/python2.6

7. Compile python
make

8. Install python
sudo make install

9. Create symbolic link to that directory
sudo ln -s /etc/python2.6/bin/python /usr/local/bin/python2.6





Ubuntu VMWare installation

OS: Ubuntu 8.04 (Hardy Heron)
VMWare version: 6.5.1

get "VMware-Workstation-
VERSION.i386.bundle" file

1. install prerequirements:
   sudo aptitude install build-essential
linux-kernel-headers linux-kernel-devel

2. Go to the folder that you have copied VMWare file

3. Install VMWare:

gksudo bash ./VMware-Workstation-6.5.0-118166.i386.bundle



referrence: https://help.ubuntu.com/community/VMware/Workstation