Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Tuesday, July 16, 2013

Immigrate data from SQLite3 to MySQL on Linux

This is a classical problem of how to immigrate data from SQLite3 to MySQL. I tried lots of scripts found online and the following one is the best suitable to me.

The code is from https://github.com/athlite/sqlite3-to-mysql/blob/master/sqlite3-to-mysql  and the author should take the whole credit.
#/usr/bin/env sh
sed \
-e '/PRAGMA.*;/ d' \
-e '/BEGIN TRANSACTION.*/ d' \
-e '/COMMIT;/ d' \
-e '/.*sqlite_sequence.*;/d' \
-e 's/"/`/g' \
-e 's/CREATE TABLE \(`\w\+`\)/DROP TABLE IF EXISTS \1;\nCREATE TABLE \1/' \
-e 's/\(CREATE TABLE.*\)\(PRIMARY KEY\) \(AUTOINCREMENT\)\(.*\)\();\)/\1AUTO_INCREMENT\4, PRIMARY KEY(id)\5/' \
-e "s/'t'/1/g" \
-e "s/'f'/0/g" \
$1
 Here are the full process of immigrating SQLite3 to MySQL in Linux (Ubuntu for me).
1) Make sure that you have installed sqlite3 which is a management software for sqlite database. Otherwise,
    $  sudo apt-get install sqlite3
2) Save the above code in a file like sqlite32mysql.sh and assign execute privilege.
    $  chmod +x sqlite32mysql.sh
3) If you don't have a database, then create one
     mysql -u xx -p xx -h 127.0.0.1 "CREATE DATABASE sample IF NOT EXIST"
4) If you'd like only import the data to old tables,
      $  sqlite3 your_sqlite3_db.db .dump|grep "^INSERT"| ./sqlite32mysql.sh >dump.sql
   Otherwise create new tables,
     $   sqlite3 your_sqlite3_db.db .dump| ./sqlite32mysql.sh >dump.sql
5) If there are still some records cannot be imported correctly, do it separately using the following command   to grab them out.
     $ sed -n "starter_num, end_line_num p" dump.sql > manual.sql
6) Load the dump.sql using mysql.
    $ mysql -u xx -p xx -h 127.0.0.1 sample <dump.sql

BINGO!

Friday, January 25, 2013

Problems met when installing ubuntu with RAID1

0. "BOOTMGR is missing" when installing from usb
A: Format the drive as FAT (not FAT32)


1. Unable to install GRUB in /dev/sdb
A: From the link http://askubuntu.com/questions/43036/how-do-i-install-grub-on-a-raid-system-installation

Many of the answers here are just plain incorrect, telling you to disable BIOS RAID! The correct solution is atthis blog entry. I'll summarize it below.
At the stage of the install where it is attempting to install GRUB it will detect as
/dev/mapper
This is incomplete! That's why the GRUB install fails.
You need the actual name of the RAID array to install to. So during that step, pressctrl+alt+F2 to drop to a busybox terminal, then enter
ls -l /dev/mapper
Pick out the name of your array from the list shown, then press ctrl+alt+F1 to switch back to the install (you can switch back and forth as much as you like with no problems) and enter it in the field as
/dev/mapper/{your array name}
then GRUB installs perfectly and you're ready to go, with a proper BIOS RAID array intact.
It works in my case...

2. What is the default root password of ubuntu?
A: just sudo -i to enter the root mode. 

3. How to enter graphical mode from command line?
A: Plz refer to  http://www.linuxquestions.org/questions/ubuntu-63/%5Bstartx-problem%5D-startx-goes-to-black-grey-screen-and-comes-back-to-command-prompt-853802/
sudo apt-get install xinit
sudo apt-get install ubuntu-desktop  (it takes a long long time...)