Adding Database Tables and Data To A Mysql Database: Their Respective Owners
Adding Database Tables and Data To A Mysql Database: Their Respective Owners
Adding Database Tables and Data To A Mysql Database: Their Respective Owners
com
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of
their respective owners.
2
4. You are going to create a database that will hold some HR information about its employees.
Enter the following command:
create database hr;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of
their respective owners.
3
5. Set the new hr database to be the one in use by entering the following command:
use hr;
6. You have been provided with a SQL script that will populate the hr database with tables
and data. Copy the MySQL_Schema_HR.sql file into a sql directory within the
JavaProgramming directory on the C Drive.
Run the script by entering the following command:
source c:/JavaProgramming/sql/MySQL_Schema_HR.sql;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of
their respective owners.
4
8. To view the contents of each table you can run the following select command:
SELECT *
FROM departments;
Substitute the departments table for employees, job_history and jobs to view the content
of the remaining tables.
Accessing the MySQL database properties.
Now that the required data is in the database the following commands will be useful for when
you want to connect to the database via JDBC.
9. To view the current username and database location enter the following command:
select user();
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of
their respective owners.
5
10. To view the port number (required to access the database from Eclipse) enter the following
command:
SHOW variables
WHERE variable_name = 'port';
This shows the default port address of 3306 for a MySQL database. Take a note of the
settings that you have returned from your system as you will need them later.
11. Type exit to close the command line interface (not the database that is running in the
background as a service).
exit;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of
their respective owners.