SlideShare une entreprise Scribd logo
1  sur  64
COP 4610L: Applications in the Enterprise Spring 2006 Introduction To MySQL – Part 2 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/spr2006
Manipulating Tables in MySQL  (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Manipulating Tables in MySQL  (cont.) MySQL Table Types ISAM, HEAP, and MyISAM are available for MySQL versions 3.23.6 or later. MERGE, BDB, and InnoDB are available for MySQL versions 4.0 and later. Default table type is ISAM. Transaction-safe tables with row locking Transaction-safe tables with page locking A collection of MyISAM tables used as one table A binary portable table handler that has replaced ISAM The data for this table is only stored in memory MySQL’s original table handler Description InnoDB BDB MERGE MyISAM HEAP ISAM Table Type
Altering A Table ,[object Object],[object Object],[object Object],[object Object],[object Object]
Altering A Table  (cont.) Actions performed by   alter table  (column related) command column_name  represents the current name of the column,  column_declaration  represents the new declaration, in the same format as if it were in a  create  command. Change the table options Rename a table Drop a column and all data contained within it. Modify column declaration without renaming column Modify column declaration with renaming of column Specify new default value for a column or remove old default Add a column to the table Action Performed table_options rename [as] new_table_name drop [column]  column_name modify [column]  column_declaration change [column]  column_name column_declaration alter [column]  column_name {set default  literal  | drop default} add [column]  column_declaration [first | after  column_name ] Action Syntax
Altering A Table  (cont.) ,[object Object],Schema of bikes before alteration There are eight rows affected because this table currently contains eight tuples (rows) and the new attribute has been added to both rows. Bikes table after the addition of a new column named races_won
Altering A Table  (cont.) ,[object Object],Every tuple in the table has the default value for the new attribute.
Altering A Table  (cont.) ,[object Object],[object Object],The attribute races_won has been eliminated from the table.
Altering A Table  (cont.) ,[object Object],Schema of bikes before alteration More complicated alter table command. Bikes table after the alteration
Inserting Data Into A Table ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Form 1 Form 2 Form 3
Inserting Data Into A Table  (cont.) ,[object Object],[object Object],[object Object],[object Object]
Examples: Inserting Data Into A Table Using Form 1 for insertion – attribute order is not important.
Examples: Inserting Data Into A Table Using Form 2 for insertion – attribute order is important.
Examples: Inserting Data Into A Table Create an initially empty table Using Form 3 for insertion This table contains the name and cost of those bikes whose color was blue from the source table.
Using Scripts with MySQL ,[object Object],[object Object],[object Object],[object Object]
Using Scripts with MySQL  (cont.) Run a simple selection query on the new table. Insert some tuples Define schema for the new table. Switch to the new database. Create a new database. Drop the database if it already exists.
Using Scripts with MySQL  (cont.) Specify which script to execute Results of select query at end of script.
Using Scripts with MySQL  (cont.) Piping the script file into MySQL as input.  MySQL executes the script.  In this case displaying the results of the select query after creating the database and table as well as filling the table.  Note that MySQL exits after running the script.
Importing Data Using the  mysqlimport  Utility ,[object Object],[object Object],[object Object],[object Object],[object Object]
Importing Data Using the  mysqlimportUtility   (cont.) ,[object Object],[object Object]
Importing Data Using the   mysqlimportUtility Table updated See tables on pages 23-24 for listing of options. Importing a “data file” into a MySQL database table using the mysqlimport utility
Importing Data Using the   mysqlimportUtility Table  before  another client updated the table using the mysqlimport utility. Table  after  another client updated the table using the mysqlimport utility.
mysqlimportUtility  Options Specify the delimiter that encloses each field, default is none. --fields-enclosed-by=‘char’ Empty the table before inserting data. -d or –delete Forces mysqlimport to continue inserting data even if errors are encountered. -f or –force Causes imported rows to overwrite existing rows if they have the same unique key value. -r or –replace Specify the separator used between values of the same row, default  (tab). --fields-terminated-by=‘char’ Lock each table before importing (a good idea in general and especially on a busy server). -l or –lock Ignores rows that have the same unique key value as existing rows. -i or –ignore Action Option
mysqlimport  Utility Options  (cont.) Print help message and exit -? or –help Verbose mode, print more commentary on action. -v or –verbose Silent mode, output appears only when errors occur. -s or –silent Specify your password -p or –password Specify the separator used to terminate each row of data, default is  (newline). --lines-terminated-by=‘char’ Same as –fields-enclosed-by, but delimiter is used only to enclosed string-type columns, default is none. --fields-optionally-enclosed-by=‘char’ Import into MySQL on the named host; default is localhost. -h or –host Specify your username -u or –user Specify the escape character placed before special characters; default is  --fields-escaped-by=‘char’ Action Option
Importing Data From A File With SQL Statement   Load Data Infile ,[object Object],[object Object],[object Object],[object Object]
Importing Data From A File With SQL Statement   Load Data Infile   (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Used to load only certain columns (not entire rows) Ignores lines at the start of the file (miss header info) Sets the characters that delimit and enclose the fields and lines in the data file.  Similar to mysqlimport syntax. Same as –r and –i options in mysqlimport utility – either replace or ignore rows with duplicate keys. Either allow concurrent update or block until no other clients are reading from the specified table.  See page 32.
Load Data Infile  Example Text file containing the data to be loaded into the database table. String fields are enclosed by double quotes in this file.  Numeric values are not enclosed in quotes. Fields are delimited by commas and lines are terminated by newline characters (an invisible )
States table  before  addition of data States table  after  addition of data Load data infile statement indicating all of the parameters which describe the configuration of the input file.
Load Data Infile  Example 2 Text file containing the data to be loaded into the database table. String fields are enclosed by double quotes in this file.  Numeric values are not enclosed in quotes. Fields are delimited by commas and lines are terminated by newline characters (an invisible ) California already exists in the states table – this one will replace the value of the capital with a different value.
Same basic configuration as in previous example except that we have instructed MySQL to replace duplicate key value rows with new values (in this case replacing California’s capital). States table  before  addition of data States table  after  addition of data.  Note that California’s capital has been changed!
States table  before  addition of data Notice that running the same command on the altered table produced a different set of statistics, since all six key values appear in the infile, their corresponding values in the table are deleted and re-entered using the “new” data.
The  Ignore  Clause of the Insert Command ,[object Object],[object Object],[object Object],[object Object],[object Object]
Low Priority and Delayed Inserts ,[object Object],[object Object],[object Object],[object Object]
Inserting/Replacing Data Using  Replace ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Form 1 Form 2 Form 3
Using  replace ,[object Object],[object Object],Changing non-key values.  Simplest form of data replacement.
Using  Replace  (cont.) Specifying values for a non-existent key.  Basically the same as an insert since the key value being replaced does not currently exist.
Performing Updates on Tables ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using  update  (cont.) Global update within the relation.  All tuples have their price field increased by 5%
Using  update  (cont.) Specific update, only tuples satisfying the select condition (those with price greater than 4500) will have their price field increased by 5%.
Select Queries in MySQL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MySQL RDBMS  (cont.) ,[object Object],[object Object],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.
Authorization in MySQL ,[object Object],[object Object],[object Object],[object Object]
Tables in the   mysql   Database The mysql database contains user information Details on user privileges.  See page 43. Details about the various users.  See page 44. Specific details on privileges at the table level.  See page 45 Details on user privileges at the database level.  See page 46.
Contents of the   user   Table
Contents of the   user_info   Table
Contents of the   tables_priv   Table
Contents of the   db   Table
How The Grant Tables Work ,[object Object],[object Object],[object Object]
How The Grant Tables Work  (cont.) ,[object Object],[object Object],[object Object]
How The Grant Tables Work  (cont.) ,[object Object],[object Object]
Managing User Privileges with GRANT and REVOKE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Some of the Privileges Assigned with GRANT   Create temporary tables. CREATE TEMPORARY TABLES Ability to shutdown the MySQL server. SHUTDOWN Ability to drop databases or tables. DROP Create database or tables within a database. CREATE All privileges except for GRANT ALL or ALL PRIVILEGES Ability to insert data into tables. INSERT Ability to perform deletions from tables.  (Delete DML statements). DELETE Change a table definition using ALTER TABLE excluding the creation and dropping of indices. ALTER Operations Permitted Privilege
Displaying Privileges with   SHOW ,[object Object],[object Object],[object Object],[object Object],This user has only SELECT privilege on the testdb database. The user has all privileges on the bikes and mysql databases.
Revoking User Privileges with   REVOKE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example - Revoking User Privileges with   REVOKE User has SELECT privilege on testdb.states table. Revoking user’s SELECT privilege on testdb.states. User’s grant listing shows that they no longer have SELECT privilege on testdb.states table.
The MySQL Administrator Tool ,[object Object],[object Object],[object Object],[object Object],[object Object]
The MySQL Administrator Tool – Screen Shots Initial login screen
Initial screen after successful login.
View of user information screen.
Select a user and a database to grant or revoke privileges.
View of system catalogs which describe the databases maintained by the server.
The MySQL Query Browser Tool ,[object Object],[object Object],[object Object],[object Object],[object Object]
Result set shown for this query.  Note that this query is based on a single table, so the result set is editable.
You can manage multiple result sets simultaneously.  Statistics on query execution are always available.

Contenu connexe

Tendances (19)

Sql DML
Sql DMLSql DML
Sql DML
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Database Overview
Database OverviewDatabase Overview
Database Overview
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
Assg2 b 19121033-converted
Assg2 b 19121033-convertedAssg2 b 19121033-converted
Assg2 b 19121033-converted
 
Sql commands
Sql commandsSql commands
Sql commands
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
SQL
SQLSQL
SQL
 
Java class 8
Java class 8Java class 8
Java class 8
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statements
 
Mysql
MysqlMysql
Mysql
 
I stata
I stataI stata
I stata
 
Sql 
statements , functions & joins
Sql 
statements , functions  &  joinsSql 
statements , functions  &  joins
Sql 
statements , functions & joins
 

En vedette

Verio Virtual Private Server (VPS)
Verio Virtual Private Server (VPS)Verio Virtual Private Server (VPS)
Verio Virtual Private Server (VPS)webhostingguy
 
The Space Island Project Copyright 2003 The Space Island ...
The Space Island Project Copyright 2003 The Space Island ...The Space Island Project Copyright 2003 The Space Island ...
The Space Island Project Copyright 2003 The Space Island ...webhostingguy
 
Developer Shared Hosting
Developer Shared HostingDeveloper Shared Hosting
Developer Shared Hostingwebhostingguy
 
Building Enterprise Interoperability Applications Using Microsoft
Building Enterprise Interoperability Applications Using MicrosoftBuilding Enterprise Interoperability Applications Using Microsoft
Building Enterprise Interoperability Applications Using Microsoftwebhostingguy
 
4PSA VoipNow Plesk Module 2.0.2
4PSA VoipNow Plesk Module 2.0.24PSA VoipNow Plesk Module 2.0.2
4PSA VoipNow Plesk Module 2.0.2webhostingguy
 
Server Virtualization
Server VirtualizationServer Virtualization
Server Virtualizationwebhostingguy
 
The Shortcut Guide to SQL Server Infrastructure Optimization
The Shortcut Guide to SQL Server Infrastructure OptimizationThe Shortcut Guide to SQL Server Infrastructure Optimization
The Shortcut Guide to SQL Server Infrastructure Optimizationwebhostingguy
 

En vedette (8)

Verio Virtual Private Server (VPS)
Verio Virtual Private Server (VPS)Verio Virtual Private Server (VPS)
Verio Virtual Private Server (VPS)
 
The Space Island Project Copyright 2003 The Space Island ...
The Space Island Project Copyright 2003 The Space Island ...The Space Island Project Copyright 2003 The Space Island ...
The Space Island Project Copyright 2003 The Space Island ...
 
Developer Shared Hosting
Developer Shared HostingDeveloper Shared Hosting
Developer Shared Hosting
 
Building Enterprise Interoperability Applications Using Microsoft
Building Enterprise Interoperability Applications Using MicrosoftBuilding Enterprise Interoperability Applications Using Microsoft
Building Enterprise Interoperability Applications Using Microsoft
 
4PSA VoipNow Plesk Module 2.0.2
4PSA VoipNow Plesk Module 2.0.24PSA VoipNow Plesk Module 2.0.2
4PSA VoipNow Plesk Module 2.0.2
 
Server Virtualization
Server VirtualizationServer Virtualization
Server Virtualization
 
The Shortcut Guide to SQL Server Infrastructure Optimization
The Shortcut Guide to SQL Server Infrastructure OptimizationThe Shortcut Guide to SQL Server Infrastructure Optimization
The Shortcut Guide to SQL Server Infrastructure Optimization
 
MySQL JDBC Tutorial
MySQL JDBC TutorialMySQL JDBC Tutorial
MySQL JDBC Tutorial
 

Similaire à Introduction to MySQL - Part 2

Similaire à Introduction to MySQL - Part 2 (20)

Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Module 3
Module 3Module 3
Module 3
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Adbms
AdbmsAdbms
Adbms
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
ADBMS Unit-II c
ADBMS Unit-II cADBMS Unit-II c
ADBMS Unit-II c
 
Sql statement,functions and joins
Sql statement,functions and joinsSql statement,functions and joins
Sql statement,functions and joins
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
Mysql1
Mysql1Mysql1
Mysql1
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Mandatory sql functions for beginners
Mandatory sql functions for beginnersMandatory sql functions for beginners
Mandatory sql functions for beginners
 
2. DBMS Experiment - Lab 2 Made in SQL Used
2. DBMS Experiment - Lab 2 Made in SQL Used2. DBMS Experiment - Lab 2 Made in SQL Used
2. DBMS Experiment - Lab 2 Made in SQL Used
 
SQL
SQLSQL
SQL
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 

Plus de 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 Frameworkwebhostingguy
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guidewebhostingguy
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3webhostingguy
 
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 serverswebhostingguy
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidationwebhostingguy
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreementwebhostingguy
 
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 Infrastructurewebhostingguy
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.pptwebhostingguy
 
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 Merchandiserswebhostingguy
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Productswebhostingguy
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mbwebhostingguy
 

Plus de webhostingguy (20)

File Upload
File UploadFile Upload
File Upload
 
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
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guide
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3
 
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
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidation
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreement
 
Notes8
Notes8Notes8
Notes8
 
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 ...
 
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 ...
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructure
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.ppt
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy
 
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
 
OLUG_xen.ppt
OLUG_xen.pptOLUG_xen.ppt
OLUG_xen.ppt
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Products
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mb
 
Reseller's Guide
Reseller's GuideReseller's Guide
Reseller's Guide
 

Introduction to MySQL - Part 2

  • 1. COP 4610L: Applications in the Enterprise Spring 2006 Introduction To MySQL – Part 2 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/spr2006
  • 2.
  • 3. Manipulating Tables in MySQL (cont.) MySQL Table Types ISAM, HEAP, and MyISAM are available for MySQL versions 3.23.6 or later. MERGE, BDB, and InnoDB are available for MySQL versions 4.0 and later. Default table type is ISAM. Transaction-safe tables with row locking Transaction-safe tables with page locking A collection of MyISAM tables used as one table A binary portable table handler that has replaced ISAM The data for this table is only stored in memory MySQL’s original table handler Description InnoDB BDB MERGE MyISAM HEAP ISAM Table Type
  • 4.
  • 5. Altering A Table (cont.) Actions performed by alter table (column related) command column_name represents the current name of the column, column_declaration represents the new declaration, in the same format as if it were in a create command. Change the table options Rename a table Drop a column and all data contained within it. Modify column declaration without renaming column Modify column declaration with renaming of column Specify new default value for a column or remove old default Add a column to the table Action Performed table_options rename [as] new_table_name drop [column] column_name modify [column] column_declaration change [column] column_name column_declaration alter [column] column_name {set default literal | drop default} add [column] column_declaration [first | after column_name ] Action Syntax
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. Examples: Inserting Data Into A Table Using Form 1 for insertion – attribute order is not important.
  • 13. Examples: Inserting Data Into A Table Using Form 2 for insertion – attribute order is important.
  • 14. Examples: Inserting Data Into A Table Create an initially empty table Using Form 3 for insertion This table contains the name and cost of those bikes whose color was blue from the source table.
  • 15.
  • 16. Using Scripts with MySQL (cont.) Run a simple selection query on the new table. Insert some tuples Define schema for the new table. Switch to the new database. Create a new database. Drop the database if it already exists.
  • 17. Using Scripts with MySQL (cont.) Specify which script to execute Results of select query at end of script.
  • 18. Using Scripts with MySQL (cont.) Piping the script file into MySQL as input. MySQL executes the script. In this case displaying the results of the select query after creating the database and table as well as filling the table. Note that MySQL exits after running the script.
  • 19.
  • 20.
  • 21. Importing Data Using the mysqlimportUtility Table updated See tables on pages 23-24 for listing of options. Importing a “data file” into a MySQL database table using the mysqlimport utility
  • 22. Importing Data Using the mysqlimportUtility Table before another client updated the table using the mysqlimport utility. Table after another client updated the table using the mysqlimport utility.
  • 23. mysqlimportUtility Options Specify the delimiter that encloses each field, default is none. --fields-enclosed-by=‘char’ Empty the table before inserting data. -d or –delete Forces mysqlimport to continue inserting data even if errors are encountered. -f or –force Causes imported rows to overwrite existing rows if they have the same unique key value. -r or –replace Specify the separator used between values of the same row, default (tab). --fields-terminated-by=‘char’ Lock each table before importing (a good idea in general and especially on a busy server). -l or –lock Ignores rows that have the same unique key value as existing rows. -i or –ignore Action Option
  • 24. mysqlimport Utility Options (cont.) Print help message and exit -? or –help Verbose mode, print more commentary on action. -v or –verbose Silent mode, output appears only when errors occur. -s or –silent Specify your password -p or –password Specify the separator used to terminate each row of data, default is (newline). --lines-terminated-by=‘char’ Same as –fields-enclosed-by, but delimiter is used only to enclosed string-type columns, default is none. --fields-optionally-enclosed-by=‘char’ Import into MySQL on the named host; default is localhost. -h or –host Specify your username -u or –user Specify the escape character placed before special characters; default is --fields-escaped-by=‘char’ Action Option
  • 25.
  • 26.
  • 27. Load Data Infile Example Text file containing the data to be loaded into the database table. String fields are enclosed by double quotes in this file. Numeric values are not enclosed in quotes. Fields are delimited by commas and lines are terminated by newline characters (an invisible )
  • 28. States table before addition of data States table after addition of data Load data infile statement indicating all of the parameters which describe the configuration of the input file.
  • 29. Load Data Infile Example 2 Text file containing the data to be loaded into the database table. String fields are enclosed by double quotes in this file. Numeric values are not enclosed in quotes. Fields are delimited by commas and lines are terminated by newline characters (an invisible ) California already exists in the states table – this one will replace the value of the capital with a different value.
  • 30. Same basic configuration as in previous example except that we have instructed MySQL to replace duplicate key value rows with new values (in this case replacing California’s capital). States table before addition of data States table after addition of data. Note that California’s capital has been changed!
  • 31. States table before addition of data Notice that running the same command on the altered table produced a different set of statistics, since all six key values appear in the infile, their corresponding values in the table are deleted and re-entered using the “new” data.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36. Using Replace (cont.) Specifying values for a non-existent key. Basically the same as an insert since the key value being replaced does not currently exist.
  • 37.
  • 38. Using update (cont.) Global update within the relation. All tuples have their price field increased by 5%
  • 39. Using update (cont.) Specific update, only tuples satisfying the select condition (those with price greater than 4500) will have their price field increased by 5%.
  • 40.
  • 41.
  • 42.
  • 43. Tables in the mysql Database The mysql database contains user information Details on user privileges. See page 43. Details about the various users. See page 44. Specific details on privileges at the table level. See page 45 Details on user privileges at the database level. See page 46.
  • 44. Contents of the user Table
  • 45. Contents of the user_info Table
  • 46. Contents of the tables_priv Table
  • 47. Contents of the db Table
  • 48.
  • 49.
  • 50.
  • 51.
  • 52. Some of the Privileges Assigned with GRANT Create temporary tables. CREATE TEMPORARY TABLES Ability to shutdown the MySQL server. SHUTDOWN Ability to drop databases or tables. DROP Create database or tables within a database. CREATE All privileges except for GRANT ALL or ALL PRIVILEGES Ability to insert data into tables. INSERT Ability to perform deletions from tables. (Delete DML statements). DELETE Change a table definition using ALTER TABLE excluding the creation and dropping of indices. ALTER Operations Permitted Privilege
  • 53.
  • 54.
  • 55. Example - Revoking User Privileges with REVOKE User has SELECT privilege on testdb.states table. Revoking user’s SELECT privilege on testdb.states. User’s grant listing shows that they no longer have SELECT privilege on testdb.states table.
  • 56.
  • 57. The MySQL Administrator Tool – Screen Shots Initial login screen
  • 58. Initial screen after successful login.
  • 59. View of user information screen.
  • 60. Select a user and a database to grant or revoke privileges.
  • 61. View of system catalogs which describe the databases maintained by the server.
  • 62.
  • 63. Result set shown for this query. Note that this query is based on a single table, so the result set is editable.
  • 64. You can manage multiple result sets simultaneously. Statistics on query execution are always available.

Notes de l'éditeur

  1. Phd, MS, Under