DatabaseManagment Systems (DMS) Author: Mary Waswa-Wilson Date: 5th June 2013 Exercise and Discussion In a group: Installation and Securing MySQL Install XAMPP Secure MySQL Come up with a database structure for a Bookstore that captures information on stock, staff, purchases and sales Normalise all the tables Identify relevant data types (properties) for each entity in all tables e.g. integer, date etc Create the database with all relegate tables identified above using phpmyadmin Populate the tables with sample data using phpmyadmin Query the data using phpmyadmin and copy the query in the query field and run it on command line Back up the data On completion of this exercise participants should be able to: 1. Design a database 2. Populate the database 3. Manage back up and restoration Exercise one: installing and securing MySQL using xampp Step 1: Download and install XAMMP Go to: http://www.apachefriends.org/en/xampp.html and click the link for your Operating System. Step 2: Once your download is complete, install the program, click on "Run" Step 1: Accept the default settings. A command will open and offer an initial installation prompt. Just hit the Enter key, and accept the default settings. To simplify installation, just hit ENTER when prompted on the command line. You can always change settings, by editing the configuration files later. Step 1: When your installation is complete, exit the command window by typing x on the command line. Step 1: Verifying and starting XAMMP Start the XAMPP Control Panel by clicking the short cut icon placed on the desk top. Start the Apache and MySQL components. You can also start the other components, if you plan to use them. Verify the Apache install, by clicking on the Apache administrative link in the Control Panel. Verify the MySQL installation, by clicking on the MySQL administrative link in the XAMPP Control Panel. If the verification steps are successful, XAMPP should be successfully installed on your PC. Open a browser and enter "localhost" on your address bar. You will be redirected to a page telling you that you've successfully installed xampp on your system a. Creating a Database 1. Log into the cPanel 2. Click the MySQL Databases icon under the "Databases" category 3. In the New Database field, type a name for the database. 4. Click Go Back. a. The new database will appear in the Current Databases table. b. Deleting a MySQL Database 1. Navigate to the Current Databases section 2. Click the Delete Database link next to the database you wish to delete If you would like to remove a user that has been assigned to a database, click the red "X" next to the user on this table. c. Create a database user 1. Locate the MySQL Users section of the MySQL Databases tool. To quickly find this section, click "Jump to MySQL Users". 2. Under Add New User, enter a username. Note: The username must be 7 letters or shorter. 3. Enter a password in the Password field.For help generating a strong password, click the Generate Password button. 4. Retype the password in the Password (Again) field. Exercise Two: Come up with a database structure for a Bookstore that captures information on stock, staff, purchases and sales Step 1: Database Structure Step 2: Database Name: MyBookstore Tables: Table 1: Stock Field 1 – Stock Id Field 2 - Name Field 3 - Qty Field4 – Location Field 5 – reorder level Field 6 – Buying Price Field 2 – Selling Price Table 2: Staff Field 1 – Staff Id Field 2 – Staff Name Field 3 – Position Field4 – Location Field 5 – Job category Table 3: Purchases Field 1 – Purchase Id Field 2 – Client Name Field 3 - Qty Field4 – Location Field 5 – Order date Field 6 – Delivery date Field 1 – Buying Price Table 4: Sales Field 1 – Sales Id Field 2 - Name Field 3 - Qty Field4 – Location Field 5 – reorder level Normalise all the tables Identify relevant data types (properties) for each entity in all tables e.g. integer, date etc Create the database with all relegate tables identified above using phpmyadmin Populate the tables with sample data using phpmyadmin Query the data using phpmyadmin and copy the query in the query field and run it on command line Backup of Mysql database Open phpMyAdmin. 1. Click Export in the Menu to get to where you can backup you MySql database. 2. Make sure that you have selected to export your entire database, and not just one table. There should be as many tables in the export list as showing under the database name. 3. Select"SQL"-> for output format, Check "Structure" and "Add AUTO_INCREMENT" value. Check "Enclose table and field name with backquotes". Check "DATA", check use "hexadecimal for binary field". Export type set to "INSERT". 4. Check "Save as file", do not change the file name, use compression if you want. Then click "GO" to download the backup file. Restoring a backup of a MySQL database 1. To restore a database, you click the SQL tab. 2. On the "SQL"-page , unclick the show query here again. 3. Browse to your backup of the database. 4. Click Go.