r2 - 06 Dec 2006 - 23:38:29 - DaveMorrisYou are here: TWiki >  Astrogrid Web  >  DaveMorris > DataAccess20061206
Shell script command to load a FITS file into a mysql database.

Location of the FITS file : http://www.mrao.cam.ac.uk/~tsg25/Documents/Oxford/FLSGMRT.FIT

Documentation for the STILTS library : http://www.star.bris.ac.uk/~mbt/stilts/

Documentation for the MySql? database : http://dev.mysql.com/doc/refman/4.1/en/index.html

Starting with RedHat? Fedora installed on a VM at Leicester, with Java JDK-1.5 and Tomcat-5.5.20 already installed.

First stage as root :

#
# Install the MySql database tools.
yum -y install mysql mysql-server

#
# Start the database server.
/etc/init.d/mysqld start

#
# Configure the database to restart on boot.
chkconfig mysqld on
chkconfig --list mysqld

#
# Login to the database as root.
mysql --user=root mysql

    #
    # Create our database.
    CREATE DATABASE astro ;

    #
    # Grant the required access. 
    GRANT USAGE ON *.* TO 'astro'@'localhost' IDENTIFIED BY 'pass' ;
    GRANT CREATE, DROP, SELECT, INSERT ON astro.* TO 'astro'@'localhost' IDENTIFIED BY 'pass' ;
    FLUSH PRIVILEGES ;
    
    #
    # Exit
    \q

Next stage can be done as normal user

First, setup the directories and download the tools.

#
# Create the stilts directory.
mkdir ${ASTROGRID_HOME}/stilts
mkdir ${ASTROGRID_HOME}/stilts/jars
mkdir ${ASTROGRID_HOME}/stilts/data
mkdir ${ASTROGRID_HOME}/stilts/downloads

#
# Download the stilts library.
wget -P ${ASTROGRID_HOME}/stilts/jars http://www.star.bris.ac.uk/~mbt/stilts/stilts.jar

#
# MySql Java drivers available here :
# http://dev.mysql.com/downloads/connector/j/5.0.html
# Ignore the registration form - URLs are at bottom of page.
wget -P ${ASTROGRID_HOME}/stilts/downloads http://www.mirror.ac.uk/mirror/www.mysql.org/Downloads/Connector-J/mysql-connector-java-5.0.0-beta.tar.gz

#
# Extract the jar from the tar.gz file.
tar -xz --to-stdout \
    -f ${ASTROGRID_HOME}/stilts/downloads/mysql-connector-java-5.0.0-beta.tar.gz \
    mysql-connector-java-5.0.0-beta/mysql-connector-java-5.0.0-beta-bin.jar \
    > ${ASTROGRID_HOME}/stilts/jars/mysql-java-5.0.0-beta.jar

Next, download the target FITS file and import it into the database.


#
# Download the source fits file.
wget -P ${ASTROGRID_HOME}/stilts/data http://www.mrao.cam.ac.uk/~tsg25/Documents/Oxford/FLSGMRT.FIT

#
# Run the stilts toolkit
$JAVA_HOME/bin/java \
    -classpath ${ASTROGRID_HOME}/stilts/jars/stilts.jar:${ASTROGRID_HOME}/stilts/jars/mysql-java-5.0.0-beta.jar \
    -Djdbc.drivers=com.mysql.jdbc.Driver \
    uk.ac.starlink.ttools.Stilts \
    tpipe \
    in=${ASTROGRID_HOME}/stilts/data/FLSGMRT.FIT ifmt=fits \
    omode=tosql \
    protocol=mysql host=localhost database=astro newtable=flsgmrt user=astro

Connect to the database and check the results.

#
# Connect to the database as user astro.
mysql --password=pass --user=astro astro

    #
    # Check the tables.
    SHOW TABLES ;

    #
    # Check the table structure.
    DESCRIBE flsgmrt ;

    #
    # Count the rows.
    SELECT count(ra) FROM flsgmrt ;

    #
    # Exit
    \q
Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
AstroGrid Service Click here for the
AstroGrid Service Web
This is the AstroGrid
Development Wiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback