Working with SQL Files and your Kenai Project

  1 post   Feedicon  
Replies: 0 - Last Post: October 04, 2009 03:57
by: Sonny Gauran
showing 1 - 1 of 1
 
Posted: October 04, 2009 03:57 by Sonny Gauran
Requirements:

  • Netbeans IDE - Our Kick-ass IDE
  • MySQL Connector J - Our JDBC Driver
  • MySQL Server / Command-Line Client Installed
  • World Database



Table of Contents:

  • Where to Get - Tools we use in class.
  • How to Use - How to use the World Database and your individual sql file. Here, I'll discuss how to work on dumping/importing your sql so it can be versioned in your project folder.



Contents:

Where to Get:

MySQL Connector J:
The MySQL Connector can be found at the MySQL Downloads or with a Google Search.

The World Database:
The World Database is available at the MySQL Doc Site or with a Google Search.
When you download the world database however, it requires you to copy-paste the unpacked files to the data directory of a MySQL Server. I have included the World database in sql format as world.sql in our sandbox repository at /exercises/MySQL for easy import.

ICI-CECSD Team SQLs:
All SQL Files developed by the team are available at the svn repository at /project/team/sql/. This contains the earlier sandbox.sql and the worldline.sql.


How to Use:

Importing SQL Files:

In this example, we are going to import the world.sql via the command-line.

  • What we have set-up here is a working copy from the root directory of our sandbox named icj~s located on the Desktop.
  • We also have our command-line already located inside the exercises\MySQL\ directory.


Take note: **You need to have MySQL installed**
Let's first create a database in the unit you are working on.

C:\Documents and Settings\desktopUsername\Desktop>mysql -u root -p

This will change your terminal from dos to mysql prompt:

mysql>create database worldline;
mysql>exit;

After that, you can easily import your sql into worldline by:

C:\Documents and Settings\desktopUsername\Desktop\icj~s\exercises\MySQL>mysql -u mysqlUsername -p db_name < world.sql

After running this command, mysql will prompt for a password and then afterwards import the sql to the specified database. You can follow the same format for the team's sql.

In this example, we have the command-line located inside the working copy's project\team\MySQL directory.

C:\Documents and Settings\desktopUsername\Desktop\icj~s\project\team\MySQL>mysql -u mysqlUsername -p worldline < worldline.sql

Exporting SQL Files:

For versioned SQL Files, just dump your SQL files appropriately inside the project\team\MySQL directory by following the command:

C:\Documents and Settings\desktopUsername\Desktop\icj~s\project\team\MySQL>mysqldump -u mysqlUsername -p worldline > worldline.sql

This will dump the contents of the worldline database inside worldline.sql.
To version the database sql just commit the contents of project\team\MySQL inside your working copy.

C:\Documents and Settings\desktopUsername\Desktop\icj~s\project\team\MySQL>svn commit -m "[I]" --username kenaiUsername --password kenaiPassword

If you added a new sql file inside your \project\team\MySQL working copy, most-likely it will not be versioned. So just add the file in your working copy for versioning and then commit:

C:\Documents and Settings\desktopUsername\Desktop\icj~s\project\team\MySQL>svn add yourDb.sql
C:\Documents and Settings\desktopUsername\Desktop\icj~s\project\team\MySQL>svn commit -m "New file yourDB.sql added containing the database yourDB" --username kenaiUsername --password kenaiPassword
Replies: 0 - Last Post: October 04, 2009 03:57
by: Sonny Gauran
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close