SlideShare a Scribd company logo
COP 4610L: Applications in the Enterprise Spring 2005 Introduction to MySQL– Part 1 –  School of Electrical Engineering and Computer Science University of Central Florida Instructor :  Mark Llewellyn [email_address] CSB 242, 823-2790 http://www.cs.ucf.edu/courses/cop4610L/spr2005
Database Access via JDBC The  Java Database Connectivity (JDBC)  interface enables any Java program to send SQL queries to any database, and receive back result tables with the desired data.  Similar to the basic idea of Java in writing a program that will run on any hardware platform, JDBC enables the development of programs which function with nearly all commercially available DBMSs.  Apart from the general popularity of Java, this is the fundamental reason for the widespread acceptance of JDBC. In order to guarantee the general database access, JDBC defines a certain core functionality supported by all DBMSs,  This common denominator can be implemented by JDBC. This implies that different product characteristics and manufacturer-specific optimizations are ignored by the JDBC standard.
Database Access via JDBC  (cont.) One prerequisite for the use of JDBC is the availability of a  JDBC driver  for the database being utilized. The JDBC driver translates the JDBC queries of the Java database client into the respective supplier-specific calls. The simplest version on the Windows platform is the  Open Database Connectivity (ODBC)  interface.  ODBC also enables different databases to function via a uniform interface. JDBC and ODBC are both based on the same idea.  Using the JDBC-ODBC bridge, it is possible to access an ODBC data source via JDBC.
Different Methods for Database Access The figure on the next slide summarizes the various options available for accessing a database.  The client software typically communicates with the server via a proprietary interface.  The drivers translate JDBC or ODBC commands into the respective database specific calls. The user can also access the database using an SQL specific tool. One disadvantage of the ODBC solution is that every computer on which a Java database application is to run, the ODBC connection must be configured.  This contradicts the Java principle “write once, run anywhere”.  The way around this is through the use of servlets in which the only computer on which the ODBC must be configured is the one on which the servlet engine will run.  If a database application is installed on several computers or distributed as an applet, the JDBC-ODBC bridge is not an option as the ODBC connection would have to be configured on every computer.
Summary of Database Access Methods SQL Tool JDBC Database  Driver ODBC Database  Driver Database DB-specific API Java Database Client JDBC-ODBC Bridge JDBC API ODBC API
JDBC Database Access For the time being we will focus on the JDBC API for database access and not concern ourselves with ODBC (we’ll look in more detail at ODBC later).  JDBC is almost always used with a RDBMS.  However, it can be used with any table-based data source.  This means that it also works with applications like Excel. The separation of the JDBC API from the particular database drivers enables the application developer to change the underlying database without modifying the Java code that accesses the database. Most commercially available RDBMSs provide JDBC drivers and there are many third-party JDBC drivers available. We will focus on the JDBC and use it to manipulate a MySQL database.  We’ll discuss JDBC in more detail later.
MySQL RDBMS MySQL is a  database server  (although it does come with a set of simple client programs).  The current version is 4.1.9 and can be downloaded from  www.mysql.com . It is typically used in  thin client  environments.  In other words, it is used in client-server systems where the bulk of the processing and storage takes place on the server, and the client is little more than a dumb terminal. MySQL performs multithreaded processing, which means that multiple clients are allowed to connect to it and run queries simultaneously.  This makes MySQL extremely fast and well suited to client-server environments such as Web sites and other environments that process numerous transactions for multiple users.
MySQL RDBMS  (cont.) MySQL features a user permissions system, which allows control over user’s access to the databases under MySQL control. There are very few competitors of MySQL (Oracle, Sybase, DB2, and SQL Server) that can match the level of sophistication provided by MySQL’s permissions system in terms of granularity and level of security provided. Note that I did not include Microsoft Access in the list above.  There are a couple of reasons for this; Access concentrates on the client front-end, although available in shareable versions, it lacks the management system that is a key part of any RDBMS.  Access provides virtually no user authentication capabilities nor does it have multithreading processing capabilities, in its normal form.
Starting MySQL Server On Windows, MySQL runs as a server program, which means that it is a background process that sits patiently waiting for client connections.  To start the MySQL server, open a command window, switch to the  bin  directory of your MySQL directory and enter  mysqld --console .  (Omitting –console sends error messages to .err file in data directory.) InnoDB is MySQL’s ACID compliant storage engine.  Server starts. Server finishes its startup sequence. Specifying –console prevents error message from going to .err file.
Starting MySQL Server  (cont.) Once the MySQL server is started, open another command window in which to run the client process.  The command window in which the MySQL server is executing will continue to display error messages, if any, but otherwise will not return a user prompt until the server exits. You can stop the MySQL server by executing the following command from the client window:   mysqladmin –u root shutdown The next page illustrates the execution of this command from the client window and its effect on the MySQL server.
Stopping MySQL Server Client Window Server Window A user must have the privilege of stopping the server.  The root user has this permission by default. MySQL server responds with normal shutdown sequence and responses.
Running MySQL Client Programs Under Windows You can test whether the MySQL server is working by executing any of the following commands: C:\mysql\bin\mysqlshow C:\mysql\bin\mysqlshow –u root C:\mysql\bin\mysqlshow –u root mysql C:\mysql\bin\mysqladmin version status proc C:\mysql\bin\mysql test An example of the first two formats is shown on the next slide.
Running MySQL Client Programs Under Windows (cont.) Note:  The MySQL root user is not necessarily the same as the root user in Linux/Unix systems (it might be, but it doesn’t have to be).  All MySQL requires is that you have the necessary permission to execute the command entered.  For right now we’ll assume that the only user is the root user.  We’ll set permissions later. Non root user has access only to the test  and mysql databses Root user has access to every database under MySQL control.
Running MySQL Client Programs Under Windows (cont.) This command allows you to see the current status of the MySQL server, in terms of the work being done.
Starting A MySQL Client Once the MySQL server is started, open another command window in which to run the client process.  You start a direct MySQL client application by executing the following command from the client window:   c:\mysql\bin>  mysql MySQL is awaiting commands Normal start to MySQL
Starting A MySQL Client  (cont.) Start sequence for a non-root user Start sequence for root user
Specifying A Database Within MySQL Unless, it is specifically stated, in the following slides we’ll assume that the user has root-level privileges.  To select a database for use in MySQL the  use  command must be issued.  In the example below, we’ll select the  bikedb  database. SQL acknowledges selection of  bikedb   database.
Viewing the Relations of a Database Once a database has been selected you can see the relations (tables) within that database with the  show tables  command as illustrated below. Show tables command lists all the relations within a database visible to the user.  There is only a single table in this database.
Viewing the Schema of a Relation To see the schema of a relation within a database, use the  describe  <tablename>   command as illustrated below. Specify which table’s schema to describe.  All information regarding the schema visible to the user is displayed.
Running a Simple Select Query in MySQL Within the MySQL monitor, running an SQL query is straight forward.  The example below illustrates a simple selection query on the  bikes  table of the  bikedb  database.  The tuples within the  bikes  table are displayed as the result of the query.
Creating a Database in MySQL There are two ways to create a MySQL database.  From a client command window execute the  mysqladmin  script  create  and specify the name of the database. Subsequent listing of databases shows newly created  sample  database. Specify creation of new database named  sample
Creating a Database in MySQL  (cont.) From the MySQL monitor enter  create database  <db name> Create new database from within MySQL monitor. Subsequent listing shows newly created database
Dropping a Database in MySQL There are two ways to destroy a MySQL database.  From a client command window execute the  mysqladmin  script  drop  and specify the name of the database. Specify dropping the database named  sample. MySQL gives you a warning and a bailout before the database is destroyed.
Dropping a Database in MySQL From the MySQL monitor execute the  drop database  <db name>   command. From within the MySQL monitor, no warning is given when dropping a database.  Be very sure that this is what you want to do before you do it.
Manipulating Tables in MySQL The creation of a database does not place into the database any relations.  Relations must be separately created.  To create a table within a database, first select the database (or create one if you haven’t already done so), then execute the  create table  command.
Manipulating Tables in MySQL   (cont.) Screen shot showing newly created table.
Manipulating Tables in MySQL  (cont.) The  create table  command has the following general format: create [temporary] table [if not exists]  tablename [( create_definition, ... )] [ table_options ] [ select_statement ]; If the [if not exists] clause is present, MySQL will produce an error message if a table with the specified name already exists in the database, otherwise the table is created.
Manipulating Tables in MySQL  (cont.) A temporary table exists only for the life of the current database connection.  It is automatically destroyed when the connection is closed or dies. Two different connections can use the same name for a temporary table without conflicting with one another.  Temporary tables are most useful when queries get complex and intermediate results become useful.  Also, versions of MySQL earlier than version 4.1 do not have subselect capability and temporary tables are a convenient way to simulate subselect query results. Note:  Non-root users require special permission to be able to create temporary tables.  These users must have the Create_tmp_tables privilege set in the user grant table.  We’ll see more on this later.
Creating A Temporary Table From A Select Query A SELECT query produces a result set which has been extracted from one or more tables.  A table can be created with the results of this data using the create table command.  Notice that temporary tables do not appear in a table listing.
Ad

More Related Content

What's hot (16)

Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
Ankit Dubey
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
Santosh Kumar Kar
 
Spring database - part2
Spring database -  part2Spring database -  part2
Spring database - part2
Santosh Kumar Kar
 
Jdbc
JdbcJdbc
Jdbc
Jussi Pohjolainen
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
Prabhat gangwar
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
Sandeep Rawat
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
Hemo Chella
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
Pallepati Vasavi
 
JDBC
JDBCJDBC
JDBC
People Strategists
 
jdbc document
jdbc documentjdbc document
jdbc document
Yamuna Devi
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
Mazenetsolution
 
Jdbc
JdbcJdbc
Jdbc
leminhvuong
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
Luzan Baral
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
Ankit Dubey
 
Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
Santosh Kumar Kar
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
Pallepati Vasavi
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
Mazenetsolution
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
Luzan Baral
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 

Viewers also liked (8)

Citadon Hosting Services
Citadon Hosting ServicesCitadon Hosting Services
Citadon Hosting Services
webhostingguy
 
Course Information For Week 1
Course Information For Week 1Course Information For Week 1
Course Information For Week 1
Casa Thomas Jefferson
 
Domain Migration/Administration for the College of ...
Domain Migration/Administration for the College of ...Domain Migration/Administration for the College of ...
Domain Migration/Administration for the College of ...
webhostingguy
 
WBH 4.0 Mod 6 - Server Purposing.ppt
WBH 4.0 Mod 6 - Server Purposing.pptWBH 4.0 Mod 6 - Server Purposing.ppt
WBH 4.0 Mod 6 - Server Purposing.ppt
webhostingguy
 
The Fed Under Attack
The Fed Under Attack The Fed Under Attack
The Fed Under Attack
Jeff Green
 
WebHost Manager Online Help 1.0
WebHost Manager Online Help 1.0WebHost Manager Online Help 1.0
WebHost Manager Online Help 1.0
webhostingguy
 
Official Webmaster
Official WebmasterOfficial Webmaster
Official Webmaster
webhostingguy
 
Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...
webhostingguy
 
Citadon Hosting Services
Citadon Hosting ServicesCitadon Hosting Services
Citadon Hosting Services
webhostingguy
 
Domain Migration/Administration for the College of ...
Domain Migration/Administration for the College of ...Domain Migration/Administration for the College of ...
Domain Migration/Administration for the College of ...
webhostingguy
 
WBH 4.0 Mod 6 - Server Purposing.ppt
WBH 4.0 Mod 6 - Server Purposing.pptWBH 4.0 Mod 6 - Server Purposing.ppt
WBH 4.0 Mod 6 - Server Purposing.ppt
webhostingguy
 
The Fed Under Attack
The Fed Under Attack The Fed Under Attack
The Fed Under Attack
Jeff Green
 
WebHost Manager Online Help 1.0
WebHost Manager Online Help 1.0WebHost Manager Online Help 1.0
WebHost Manager Online Help 1.0
webhostingguy
 
Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...
webhostingguy
 
Ad

Similar to Introduction to MySQL - Part 1 (20)

Jdbc
JdbcJdbc
Jdbc
Harish Khodke
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
ChagantiSahith
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
JONDHLEPOLY
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
Vikas Jagtap
 
3 jdbc
3 jdbc3 jdbc
3 jdbc
Fajar Baskoro
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2
msafad
 
jdbc
jdbcjdbc
jdbc
shreeuva
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Jdbc
JdbcJdbc
Jdbc
Mumbai Academisc
 
open data base connectivity and java database connectivity
open data base connectivity and java database connectivityopen data base connectivity and java database connectivity
open data base connectivity and java database connectivity
ssuser42b933
 
java.pptx
java.pptxjava.pptx
java.pptx
bfgd1
 
JDBC
JDBCJDBC
JDBC
Manjunatha RK
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
Rakesh Kumar Ray
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbms
KhyalNayak
 
UNIT 1 PPT- FINAL.pptx Advance Java JDBC
UNIT 1 PPT- FINAL.pptx Advance Java JDBCUNIT 1 PPT- FINAL.pptx Advance Java JDBC
UNIT 1 PPT- FINAL.pptx Advance Java JDBC
iamspidey0104
 
Accessing my sql_from_java
Accessing my sql_from_javaAccessing my sql_from_java
Accessing my sql_from_java
Tran Rean
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
kingkolju
 
4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt
NaveenKumar648465
 
Java and Database - Interacting with database
Java and Database - Interacting with databaseJava and Database - Interacting with database
Java and Database - Interacting with database
Amol Gaikwad
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
JONDHLEPOLY
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2
msafad
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
open data base connectivity and java database connectivity
open data base connectivity and java database connectivityopen data base connectivity and java database connectivity
open data base connectivity and java database connectivity
ssuser42b933
 
java.pptx
java.pptxjava.pptx
java.pptx
bfgd1
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbms
KhyalNayak
 
UNIT 1 PPT- FINAL.pptx Advance Java JDBC
UNIT 1 PPT- FINAL.pptx Advance Java JDBCUNIT 1 PPT- FINAL.pptx Advance Java JDBC
UNIT 1 PPT- FINAL.pptx Advance Java JDBC
iamspidey0104
 
Accessing my sql_from_java
Accessing my sql_from_javaAccessing my sql_from_java
Accessing my sql_from_java
Tran Rean
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
kingkolju
 
4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt
NaveenKumar648465
 
Java and Database - Interacting with database
Java and Database - Interacting with databaseJava and Database - Interacting with database
Java and Database - Interacting with database
Amol Gaikwad
 
Ad

More from webhostingguy (20)

File Upload
File UploadFile Upload
File Upload
webhostingguy
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
webhostingguy
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guide
webhostingguy
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3
webhostingguy
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web servers
webhostingguy
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidation
webhostingguy
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
webhostingguy
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
webhostingguy
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreement
webhostingguy
 
Notes8
Notes8Notes8
Notes8
webhostingguy
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
webhostingguy
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructure
webhostingguy
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.ppt
webhostingguy
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy
webhostingguy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandisers
webhostingguy
 
OLUG_xen.ppt
OLUG_xen.pptOLUG_xen.ppt
OLUG_xen.ppt
webhostingguy
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Products
webhostingguy
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mb
webhostingguy
 
Reseller's Guide
Reseller's GuideReseller's Guide
Reseller's Guide
webhostingguy
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
webhostingguy
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guide
webhostingguy
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3
webhostingguy
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web servers
webhostingguy
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidation
webhostingguy
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreement
webhostingguy
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
webhostingguy
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructure
webhostingguy
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.ppt
webhostingguy
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy
webhostingguy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandisers
webhostingguy
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Products
webhostingguy
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mb
webhostingguy
 

Introduction to MySQL - Part 1

  • 1. COP 4610L: Applications in the Enterprise Spring 2005 Introduction to MySQL– Part 1 – School of Electrical Engineering and Computer Science University of Central Florida Instructor : Mark Llewellyn [email_address] CSB 242, 823-2790 http://www.cs.ucf.edu/courses/cop4610L/spr2005
  • 2. Database Access via JDBC The Java Database Connectivity (JDBC) interface enables any Java program to send SQL queries to any database, and receive back result tables with the desired data. Similar to the basic idea of Java in writing a program that will run on any hardware platform, JDBC enables the development of programs which function with nearly all commercially available DBMSs. Apart from the general popularity of Java, this is the fundamental reason for the widespread acceptance of JDBC. In order to guarantee the general database access, JDBC defines a certain core functionality supported by all DBMSs, This common denominator can be implemented by JDBC. This implies that different product characteristics and manufacturer-specific optimizations are ignored by the JDBC standard.
  • 3. Database Access via JDBC (cont.) One prerequisite for the use of JDBC is the availability of a JDBC driver for the database being utilized. The JDBC driver translates the JDBC queries of the Java database client into the respective supplier-specific calls. The simplest version on the Windows platform is the Open Database Connectivity (ODBC) interface. ODBC also enables different databases to function via a uniform interface. JDBC and ODBC are both based on the same idea. Using the JDBC-ODBC bridge, it is possible to access an ODBC data source via JDBC.
  • 4. Different Methods for Database Access The figure on the next slide summarizes the various options available for accessing a database. The client software typically communicates with the server via a proprietary interface. The drivers translate JDBC or ODBC commands into the respective database specific calls. The user can also access the database using an SQL specific tool. One disadvantage of the ODBC solution is that every computer on which a Java database application is to run, the ODBC connection must be configured. This contradicts the Java principle “write once, run anywhere”. The way around this is through the use of servlets in which the only computer on which the ODBC must be configured is the one on which the servlet engine will run. If a database application is installed on several computers or distributed as an applet, the JDBC-ODBC bridge is not an option as the ODBC connection would have to be configured on every computer.
  • 5. Summary of Database Access Methods SQL Tool JDBC Database Driver ODBC Database Driver Database DB-specific API Java Database Client JDBC-ODBC Bridge JDBC API ODBC API
  • 6. JDBC Database Access For the time being we will focus on the JDBC API for database access and not concern ourselves with ODBC (we’ll look in more detail at ODBC later). JDBC is almost always used with a RDBMS. However, it can be used with any table-based data source. This means that it also works with applications like Excel. The separation of the JDBC API from the particular database drivers enables the application developer to change the underlying database without modifying the Java code that accesses the database. Most commercially available RDBMSs provide JDBC drivers and there are many third-party JDBC drivers available. We will focus on the JDBC and use it to manipulate a MySQL database. We’ll discuss JDBC in more detail later.
  • 7. MySQL RDBMS MySQL is a database server (although it does come with a set of simple client programs). The current version is 4.1.9 and can be downloaded from www.mysql.com . It is typically used in thin client environments. In other words, it is used in client-server systems where the bulk of the processing and storage takes place on the server, and the client is little more than a dumb terminal. MySQL performs multithreaded processing, which means that multiple clients are allowed to connect to it and run queries simultaneously. This makes MySQL extremely fast and well suited to client-server environments such as Web sites and other environments that process numerous transactions for multiple users.
  • 8. MySQL RDBMS (cont.) MySQL features a user permissions system, which allows control over user’s access to the databases under MySQL control. There are very few competitors of MySQL (Oracle, Sybase, DB2, and SQL Server) that can match the level of sophistication provided by MySQL’s permissions system in terms of granularity and level of security provided. Note that I did not include Microsoft Access in the list above. There are a couple of reasons for this; Access concentrates on the client front-end, although available in shareable versions, it lacks the management system that is a key part of any RDBMS. Access provides virtually no user authentication capabilities nor does it have multithreading processing capabilities, in its normal form.
  • 9. Starting MySQL Server On Windows, MySQL runs as a server program, which means that it is a background process that sits patiently waiting for client connections. To start the MySQL server, open a command window, switch to the bin directory of your MySQL directory and enter mysqld --console . (Omitting –console sends error messages to .err file in data directory.) InnoDB is MySQL’s ACID compliant storage engine. Server starts. Server finishes its startup sequence. Specifying –console prevents error message from going to .err file.
  • 10. Starting MySQL Server (cont.) Once the MySQL server is started, open another command window in which to run the client process. The command window in which the MySQL server is executing will continue to display error messages, if any, but otherwise will not return a user prompt until the server exits. You can stop the MySQL server by executing the following command from the client window: mysqladmin –u root shutdown The next page illustrates the execution of this command from the client window and its effect on the MySQL server.
  • 11. Stopping MySQL Server Client Window Server Window A user must have the privilege of stopping the server. The root user has this permission by default. MySQL server responds with normal shutdown sequence and responses.
  • 12. Running MySQL Client Programs Under Windows You can test whether the MySQL server is working by executing any of the following commands: C:\mysql\bin\mysqlshow C:\mysql\bin\mysqlshow –u root C:\mysql\bin\mysqlshow –u root mysql C:\mysql\bin\mysqladmin version status proc C:\mysql\bin\mysql test An example of the first two formats is shown on the next slide.
  • 13. Running MySQL Client Programs Under Windows (cont.) Note: The MySQL root user is not necessarily the same as the root user in Linux/Unix systems (it might be, but it doesn’t have to be). All MySQL requires is that you have the necessary permission to execute the command entered. For right now we’ll assume that the only user is the root user. We’ll set permissions later. Non root user has access only to the test and mysql databses Root user has access to every database under MySQL control.
  • 14. Running MySQL Client Programs Under Windows (cont.) This command allows you to see the current status of the MySQL server, in terms of the work being done.
  • 15. Starting A MySQL Client Once the MySQL server is started, open another command window in which to run the client process. You start a direct MySQL client application by executing the following command from the client window: c:\mysql\bin> mysql MySQL is awaiting commands Normal start to MySQL
  • 16. Starting A MySQL Client (cont.) Start sequence for a non-root user Start sequence for root user
  • 17. Specifying A Database Within MySQL Unless, it is specifically stated, in the following slides we’ll assume that the user has root-level privileges. To select a database for use in MySQL the use command must be issued. In the example below, we’ll select the bikedb database. SQL acknowledges selection of bikedb database.
  • 18. Viewing the Relations of a Database Once a database has been selected you can see the relations (tables) within that database with the show tables command as illustrated below. Show tables command lists all the relations within a database visible to the user. There is only a single table in this database.
  • 19. Viewing the Schema of a Relation To see the schema of a relation within a database, use the describe <tablename> command as illustrated below. Specify which table’s schema to describe. All information regarding the schema visible to the user is displayed.
  • 20. Running a Simple Select Query in MySQL Within the MySQL monitor, running an SQL query is straight forward. The example below illustrates a simple selection query on the bikes table of the bikedb database. The tuples within the bikes table are displayed as the result of the query.
  • 21. Creating a Database in MySQL There are two ways to create a MySQL database. From a client command window execute the mysqladmin script create and specify the name of the database. Subsequent listing of databases shows newly created sample database. Specify creation of new database named sample
  • 22. Creating a Database in MySQL (cont.) From the MySQL monitor enter create database <db name> Create new database from within MySQL monitor. Subsequent listing shows newly created database
  • 23. Dropping a Database in MySQL There are two ways to destroy a MySQL database. From a client command window execute the mysqladmin script drop and specify the name of the database. Specify dropping the database named sample. MySQL gives you a warning and a bailout before the database is destroyed.
  • 24. Dropping a Database in MySQL From the MySQL monitor execute the drop database <db name> command. From within the MySQL monitor, no warning is given when dropping a database. Be very sure that this is what you want to do before you do it.
  • 25. Manipulating Tables in MySQL The creation of a database does not place into the database any relations. Relations must be separately created. To create a table within a database, first select the database (or create one if you haven’t already done so), then execute the create table command.
  • 26. Manipulating Tables in MySQL (cont.) Screen shot showing newly created table.
  • 27. Manipulating Tables in MySQL (cont.) The create table command has the following general format: create [temporary] table [if not exists] tablename [( create_definition, ... )] [ table_options ] [ select_statement ]; If the [if not exists] clause is present, MySQL will produce an error message if a table with the specified name already exists in the database, otherwise the table is created.
  • 28. Manipulating Tables in MySQL (cont.) A temporary table exists only for the life of the current database connection. It is automatically destroyed when the connection is closed or dies. Two different connections can use the same name for a temporary table without conflicting with one another. Temporary tables are most useful when queries get complex and intermediate results become useful. Also, versions of MySQL earlier than version 4.1 do not have subselect capability and temporary tables are a convenient way to simulate subselect query results. Note: Non-root users require special permission to be able to create temporary tables. These users must have the Create_tmp_tables privilege set in the user grant table. We’ll see more on this later.
  • 29. Creating A Temporary Table From A Select Query A SELECT query produces a result set which has been extracted from one or more tables. A table can be created with the results of this data using the create table command. Notice that temporary tables do not appear in a table listing.

Editor's Notes

  • #2: Phd, MS, Under