using mysql with labview
TRANSCRIPT
1
11
Using MySQL with LabVIEWUsing MySQL with LabVIEW
Presented by Michael AivaliotisPresented by Michael AivaliotismmWave Integrated Solutions Inc.mmWave Integrated Solutions Inc.
2
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Overall OutlineOverall Outline
Database Terminology + TheoryDatabase Terminology + TheoryIntroduction to MySQL Introduction to MySQL Database Design and CreationDatabase Design and CreationConnectivity with LabVIEWConnectivity with LabVIEWCreating TablesCreating TablesInserting Data Into Your TablesInserting Data Into Your TablesSelecting Data From Your TablesSelecting Data From Your TablesAdvanced TopicsAdvanced Topics
3
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Relational DatabaseRelational Database
A relational database holds together a A relational database holds together a bunch of tables made up of columns and bunch of tables made up of columns and rows, and these tables rows, and these tables relate to each to each other based on values in a particular other based on values in a particular column.column.
What is a “relational” database?•Human thought consists of shortcuts and associations, and this is mimicked by a relational database. In order to understand something complex or difficult, you usually break it down into small, related chunks and try to wrap your brain around each little piece. If you can understand the individual parts and visualize the relationships, then understanding the whole should be easier. A relational database is nothing more than a container for those small pieces and relationships.
4
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Relational ExampleRelational Example
Online Store CatalogOnline Store Catalog–– Item IDItem ID–– NameName–– ColourColour–– SizeSize–– PricePrice–– DescriptionDescription Item_id
Item_nameItem_description
Item_idItem_nameItem_description
master_item
Item_idItem_colour
Item_idItem_colour
colours
Item_idItem_size
Item_idItem_size
sizes
Item_idItem_price
Item_idItem_price
prices
PK
In the real world of application development, one of the more common tasks developers perform is building a catalog for an online store - consider the store an application that is made up of smaller bits of data. For example, say you’re creating a catalog of sporting goods. Think about what makes up a good catalog. You might come up with the list a similar to the following: •The item ID •The name of the item •The color of the item •The size of the item •The price of the item •A description of the item
You could enter all of this information in one big table . If you went this a route, you would immediately run into questions like the following: •How do you enter an item that has multiple colors and sizes? •How do you represent items that are available in multiple sizes as well as multiple colors? •What happens when a blue, extra large sweatshirt is a different price than a red, small sweatshirt?
These questions are just the tip of the iceberg. Without a relational design, you would spend more time answering “what if” questions than you would developing the application.Instead of one large nightmare of a list, you could create several small, related tables:
•Master table . Each row contains a unique item ID , item name and general-description.•Colors table . Create one row for each item ID; a sweatshirt that comes in five colors would have five rows. •Sizes table. Create one row for each size available for each item ID; a sweatshirt that comes in three sizes would have three rows •Price table. One row for each combination of size and color for each item; in sweat shirt that comes in five colors with three sizes per color would have fifteen distinct entries
All of these tables are related through the use of a keyed value , the item ID.
This process of breaking up a long list of repetitive data into smaller logical structures is called normalization.
5
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Basic Database ElementsBasic Database Elements
DatabaseDatabaseTablesTablesRecordsRecordsFieldsFields–– KeysKeys–– IndexesIndexes
Your Database
Table
A B C D E F
Fields
A B C D E F
A B C D E F
A B C D E F
Row 1
Row 2
Row 3
Row 4
Records
It table is the largest of the elements in a database. In the order of creation, a table is the second in line, after creating the database itself. A database table is not a single, flat file that lives on your file system. When you work with the database, you’re not opening a file and inserting data then closing the file until you needed again. Instead , you use an interface to the database and issue queries that manipulate your tables and the information they store. Once tables are created, you can delete them and alter their structures using queries. Because a table is a container for data, when you drop a table , you are deleting all the data in it. Similarly, when you alter a table, alterations affect the data inside it.
Fields give structure to a table and provide a place to store data. Using this spreadsheet analogy, a field is much like a column. You can have up to 3,398 fields in each MySQL database table, but If you do, you might want to take a look at redesigning, or normalizing, your database! You will create your fields at the same time that you create your tables. In fact, defining your fields is the most important part of the table creation command. When you define the fields you want to use in your tables, you need two things: the type and the length. Properly defining your fields is crucial for creating an efficient database system. If you want to store a four digit number, such as 4,289, in your table, it’s best to define that field as a SMALLINT which is meant to hold numbers from zero to 65,535. An example of an incorrect if the mission would be to use the text type, which is meant for data up to 65,535 characters in length.
A record is an entry in your table. A record is like a row of data, with an entry in each column (field). Records can beat complete –all fields are filled in with accurate data-or incomplete. Incomplete may or may not mean empty. Depending on how you defined the fields in your table, you can add default values for empty fields within a record. , Having complete records, whether with actual values or default values, is important to maintaining the accuracy of your data.
6
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Understanding KeysUnderstanding KeysKeys are special Fields that are defined within Keys are special Fields that are defined within the table creation querythe table creation queryUnique KeysUnique Keys–– All data in that field for all records must be unique. All data in that field for all records must be unique.
Cannot enter duplicate data for that field.Cannot enter duplicate data for that field.–– You can have several unique keys per table.You can have several unique keys per table.
Primary KeysPrimary Keys–– All data in that field for all records must be unique.All data in that field for all records must be unique.–– A Primary Key is the main link between two or more A Primary Key is the main link between two or more
tables.tables.–– There can only be one primary key per table.There can only be one primary key per table.
Keys can be very powerful elements of your MySQL tables and records. As you create well designed databases for use in applications, you will use keys to tie your tables together. Fields are defined as keys within the table creation query. Currently supports two types of keys , unique and primary. When you define a field as unique, you are telling MySQL that no matter what you try, you should never be able to insert the exact same data in that field for more than one row/record.
A primary key is similar to a unique key in that both types of keys must contain unique values, but a primary key acts as the main link between two or more tables. There can be only one primary key per table, but you can have several unique keys.
7
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Primary Key ExamplePrimary Key ExampleAutomatically incrementing ID field in a tableAutomatically incrementing ID field in a tableid from orders table is the primary key.id from orders table is the primary key.This key value is used many times in the This key value is used many times in the items_ordered table.items_ordered table.This ties one or more items ordered to a particular This ties one or more items ordered to a particular order.order.The line drawn between the tables shows this The line drawn between the tables shows this relationshiprelationshipPK=primary keyPK=primary key
idship_nameship_addressship_methodorder_date
idship_nameship_addressship_methodorder_date
orders
idorder_idItem_idItem_qty
idorder_idItem_idItem_qty
Items_ordered
PK PK
8
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Understanding IndexesUnderstanding IndexesSame as Index in the back of a Book.Same as Index in the back of a Book.Primary key is automatically indexedPrimary key is automatically indexedCan manually add indexes that mimic “select” Can manually add indexes that mimic “select” queriesqueriesSpeedSpeed–– Selecting data on indexed records return results faster Selecting data on indexed records return results faster
because queries execute faster.because queries execute faster.–– Adding records to a table who’s value must be indexed Adding records to a table who’s value must be indexed
is slower.is slower.–– TradeTrade--off must be made and a decision to add an index off must be made and a decision to add an index
or not.or not.
Database indexes are functionally similar to the index in the back of a book .indexes help you find things quickly. A field in a table as a primary key, MySQL automatically adds that information to an index. You can also manually add indexes to your table, in order to index fields other than the primary key field or to index fields that provide indexes, which are combinations of one or more fields.
When you select to records that have been indexed by the database, the query will execute more quickly and therefore return a result more quickly than if the table has no indexes. Conversely, when you add a record to a table that must index a value , the query is a bit slower than when an index is not required. Therefore, you have to decide when it is best to add more indexes and when it is best to just leave well enough alone. In most cases, you can count on having indexes to tables that are more read then write, in other words tables whose primary function is to hold data for display rather than to store data for occasional use.
You can create additional indexes that mimic common select queries. For example if your application calls for a query that selects all items that are blue (a color) and large (a size) you can add an index that is a combination of the two fields color and size . An index on the item ID would not speed up the query, but this multi-column index would.
9
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Indexing ExampleIndexing Example
Common practice is to add indexes to Common practice is to add indexes to tables that are read from more than they tables that are read from more than they are written to.are written to.A good table for indexing would be a list of A good table for indexing would be a list of hardware with specifications. This table hardware with specifications. This table would be referenced in a test configuration would be referenced in a test configuration profile. Multiple reads and few writes.profile. Multiple reads and few writes.
10
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Good Database DesignGood Database Design
Good database performance relies on a Good database performance relies on a good database designgood database designDatabase must be easy to maintainDatabase must be easy to maintainMust store limited repetitive dataMust store limited repetitive dataMore work in the design and planning More work in the design and planning phase will avoid rephase will avoid re--work down the road.work down the road.Key Considerations:Key Considerations:–– Investigate table relationshipsInvestigate table relationships–– Perform normalizationPerform normalization
Good database design is crucial for a high performance application. If the database doesn’t have optimized relationships, normalization , it won’t be able to perform as efficiently as possible.
Beyond performance is the issue of maintenance. Your database should be easy to maintain. This includes storing a limited amount of repetitive data. If you have a lot of repetitive data and one instance of that data undergoes a change , that change has to be made for all occurrences of the data. To eliminate duplication and enhance your ability to maintain the data, you would create a table of possible values and use a key to refer to the value. That way, If the value changes names, the change occurs only once in the master table. The reference remains the same throughout the other tables.
The benefits of a well planned and designed database are numerous, and It stands to reason that the more work you do up front, the less you have to do later. A really bad time for a database redesign is after the public release of an application using it , and the results are costly.
11
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
RelationshipsRelationships
There are three relationship types There are three relationship types between tables.between tables.–– OneOne--toto--oneone–– OneOne--toto--manymany–– ManyMany--toto--manymany
12
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
OneOne--toto--One RelationshipsOne Relationships
Key appears only Key appears only once in a related once in a related tabletableExample: Each Example: Each employee is employee is assigned only one assigned only one computercomputer
EmployeeIDDeptIDFirstNameLastNameComputerID
EmployeeIDDeptIDFirstNameLastNameComputerID
employees
ComputerIDComputerDesc
ComputerIDComputerDesc
computers
PK PK
13
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
OneOne--toto--Many RelationshipsMany Relationships
Key from one table Key from one table appears multiple appears multiple times in a related times in a related table. Most table. Most common form.common form.Example: Many Example: Many employees belong employees belong to the same to the same departmentdepartment
EmployeeIDDeptIDFirstNameLastName
EmployeeIDDeptIDFirstNameLastName
employees
DeptIDDeptName
DeptIDDeptName
departments
PK PK
14
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
ManyMany--toto--Many RelationshipsMany Relationships
Primary key from first table appears many times Primary key from first table appears many times in second table.in second table.Primary key from second table appears many Primary key from second table appears many times in first table.times in first table.These relationships should be converted to OneThese relationships should be converted to One--toto--ManyManyExample:Example:–– A student will take more than one class at a time, and A student will take more than one class at a time, and
a class will always contain more than one student.a class will always contain more than one student.
15
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
ManyMany--toto--Many RelationshipsMany Relationships
Requires creation of intermediate table, Requires creation of intermediate table, one that sits between the two tables and one that sits between the two tables and essentially maps them together.essentially maps them together.
StudentIDFirstNameLastName
StudentIDFirstNameLastName
students
StudentIDClassID
StudentIDClassID
Students_classes_map
PK ClassIDClassDesc
ClassIDClassDesc
classes
PKPK
16
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
NormalizationNormalization
A set of rules that will help you optimize A set of rules that will help you optimize your database design.your database design.The rules are called The rules are called normal forms.normal forms.There are 3 normal form levels. Each level There are 3 normal form levels. Each level has a set of rules.has a set of rules.–– First normal formFirst normal form–– Second normal formSecond normal form–– Third normal formThird normal form
Normalization was developed by an IBM researcher named E F. Codd in the early 1970s . A relational database is merely a collection of data, organized in a particular manner, and doctor Codd created a series of rules called normal forms that help Define that organization.
There are two goals of the normalization process: eliminate redundant data (for example, storing the same data in more than one table) and ensure data dependencies make sense (only storing related data in a table). Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data is logically stored.
17
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Normalization Normalization –– Flat TableFlat TableYou start with a single flat table that contains all possible daYou start with a single flat table that contains all possible data. Very ta. Very inefficient and consumes more physical space that it should.inefficient and consumes more physical space that it should.We will use an example of a DUT test. Each DUT test requires 2 We will use an example of a DUT test. Each DUT test requires 2 power supplies. Each record will contain information on the testpower supplies. Each record will contain information on the test, , equipment used, DUT information, operator and test status (passequipment used, DUT information, operator and test status (pass--Fail).Fail).
OperatorPowerSupply2
Make_Model_SNPowerSupply1
Make_Model_SNTestStatusDUT
SN_PN_LOTTest
DescriptionTestDate
Before launching into the first normal form, you have to start with something that needs to be fixed. In the case of a database, it’s the flat table. The flat table is like a spreadsheet many, many columns. All the data you could possibly want is right there in that flat table. This scenario Is inefficient and consumes more physical space on your hard drive then a normalized database. Eliminating redundancy is the first step in normalization, so next we will take this flat table to first normal form. If this table remained in its flat format, you could have a lot of unclaimed space, and a lot of space being used unnecessarily. This is not an efficient table design.
18
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Normalization Normalization –– First Normal Form First Normal Form
Identify each row with a unique column or Identify each row with a unique column or set of columns (the primary key) set of columns (the primary key) Each field (column) must contain only one Each field (column) must contain only one value (be atomic).value (be atomic).Eliminate duplicative columns from the Eliminate duplicative columns from the same table same table Create separate tables for each group of Create separate tables for each group of related data related data
19
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
TestIDTestDateTestDescriptionOperatorFirstNameOperatorLastNameTestStatusDUT_ID
TestIDTestDateTestDescriptionOperatorFirstNameOperatorLastNameTestStatusDUT_ID
Normalization Normalization –– First Normal FormFirst Normal Form
Primary and unique Primary and unique keys were addedkeys were addedDUT, operator and DUT, operator and supply information supply information was made atomicwas made atomicSeparate tables were Separate tables were made for related datamade for related dataTests require multiple Tests require multiple suppliessuppliesDUT’s can be tested DUT’s can be tested multiple timesmultiple times
PKTestIDSupplyIDSupplyMakeSupplyModelSupplySN
TestIDSupplyIDSupplyMakeSupplyModelSupplySN
Test_Supplies
DUT_IDDUT_SNDUT_PNDUT_LOT
DUT_IDDUT_SNDUT_PNDUT_LOT
DUT’s
PK
Tests
SupplyID is a unique key.
20
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Normalization Normalization –– Second Normal Second Normal FormForm
Create separate tables for sets of values Create separate tables for sets of values that apply to multiple recordsthat apply to multiple recordsCreate relationships between these new Create relationships between these new tables and their predecessors through the tables and their predecessors through the use of foreign keys (FK). use of foreign keys (FK).
21
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
DUT_IDDUT_SNDUT_PNDUT_LOT
DUT_IDDUT_SNDUT_PNDUT_LOT
DUT’s
Normalization Normalization –– Second Normal Second Normal FormForm
SupplyIDSupplyMakeSupplyModelSupplySN
SupplyIDSupplyMakeSupplyModelSupplySN
PowerSuppliesPK
OperatorIDOperatorFirstNameOperatorLastName
OperatorIDOperatorFirstNameOperatorLastName
Operators
PK
TestIDTestDateTestDescriptionTestStatusDUT_ID (FK)OperatorID (FK)
TestIDTestDateTestDescriptionTestStatusDUT_ID (FK)OperatorID (FK)
PK
Tests
TestIDSupplyID
TestIDSupplyID
Test_SuppliesPK
22
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Normalization Normalization –– Second Normal Second Normal FormForm
Power supply fields are not related to Power supply fields are not related to TestIDTestID so it should be placed into separate so it should be placed into separate table. Additional supplies can easily be table. Additional supplies can easily be added this way.added this way.Operator table created because it is a Operator table created because it is a repeating value and possibly very few repeating value and possibly very few operatorsoperators
23
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Normalization Normalization –– Third Normal FormThird Normal Form
Remove fields (columns) that are not Remove fields (columns) that are not dependent upon the primary key.dependent upon the primary key.–– The fields of a table should be mutually The fields of a table should be mutually
independent independent
24
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Normalization Normalization –– Third Normal FormThird Normal Form
SupplyIDSupplyMakeSupplyModelSupplySN
SupplyIDSupplyMakeSupplyModelSupplySN
PowerSuppliesPK
DUT_IDDUT_SNLOT_ID (FK)PN_ID (FK)
DUT_IDDUT_SNLOT_ID (FK)PN_ID (FK)
DUT’s
OperatorIDOperatorFirstNameOperatorLastName
OperatorIDOperatorFirstNameOperatorLastName
Operators
PK
PN_IDDUT_PN
PN_IDDUT_PN
Part Numbers
PKTestIDTestDateTestDescriptionTestStatusDUT_ID (FK)OperatorID (FK)
TestIDTestDateTestDescriptionTestStatusDUT_ID (FK)OperatorID (FK)
PK
TestsLOT_IDLotNumber
LOT_IDLotNumber
LOTs
PK
PK
TestIDSupplyID
TestIDSupplyID
Test_Supplies
25
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Normalization Normalization –– Third Normal FormThird Normal Form
Many Serial Numbers can be tested from the Many Serial Numbers can be tested from the same Part Numbersame Part NumberMany Serial Numbers can be tested from the Many Serial Numbers can be tested from the same Lot Numbersame Lot NumberThis can be applied further to the Power Supply This can be applied further to the Power Supply table. We can break out the MAKE into a table. We can break out the MAKE into a separate table etc.separate table etc.If we add more fields later in the design, we If we add more fields later in the design, we should go back and review our normal form should go back and review our normal form conformance from the start.conformance from the start.
26
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
General Design GuidelinesGeneral Design Guidelines
Perform In this order:Perform In this order:–– Define the objectiveDefine the objective–– Design the data structures (tables, fields)Design the data structures (tables, fields)–– Discern relationshipsDiscern relationships–– Define and implement business rulesDefine and implement business rules–– Create your LabVIEW applicationCreate your LabVIEW application
27
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
What is MySQL? What is MySQL?
MySQL is a relational database management MySQL is a relational database management system (RDBMS)system (RDBMS)Main features:Main features:–– SpeedSpeed
Multithreaded server Multithreaded server
–– Portability (across different OS’s)Portability (across different OS’s)–– Ability to interface with any programming languageAbility to interface with any programming language
PHP, Perl, C/C++, Java, Python, Tcl, ODBC.PHP, Perl, C/C++, Java, Python, Tcl, ODBC.
–– Price (open source)Price (open source)
MySQL is the most widely used open source database, with several million users. In addition to storing all your databases, tables, columns, and rows (and data), my SQL manages them as one entity . Users are assigned access levels and permissions, all managed by the MySQL RDBMS. MySQL also logs the actions of these users and manages the responses to queries.
MySQL Is a multithreaded server, meaning that each time a connection is made , a new server processes is started. Connections to MySQL do not share processes, so when one process ends unexpectedly or overloads the server by using an inordinate amount of memory, just that single processes is shutdown, and the entire server does not come crashing to a halt. This feature also increases the overall speed of MySQL.
28
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Licensing Licensing
You can use MySQL free without a license You can use MySQL free without a license except for the following conditions:except for the following conditions:–– Using MySQL as an embedded server in an Using MySQL as an embedded server in an
application that is not licensed under the GNU public application that is not licensed under the GNU public license license
–– Developing a commercial application that will work Developing a commercial application that will work only with MySQL and shipping MySQL as part of the only with MySQL and shipping MySQL as part of the application application
–– Distributing MySQL and not providing the source Distributing MySQL and not providing the source code of MySQL as defined in the GNU public license code of MySQL as defined in the GNU public license
If you’re using the open source MySQL from MySQL AB, its Is likely that you don’t need to purchase a license and instead can use MySQL freely for whatever you do.
29
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Installing MySQL ServerInstalling MySQL Server
Download from: Download from: http://http://www.mysql.comwww.mysql.com//Install Version for your platform (Windows Install Version for your platform (Windows version discussed here)version discussed here)This is the server which you can run on This is the server which you can run on the same machine as your application or the same machine as your application or can be on a remote (networked) PC.can be on a remote (networked) PC.After installation execute the following file: After installation execute the following file: c:c:\\mysqlmysql\\binbin\\WinMySQLadminWinMySQLadmin
30
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Installing MySQL ServerInstalling MySQL Server
31
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Running MySQL ServerRunning MySQL Server
Run the WinMySQLadmin utility. The win MySQL admin application will finish setting up the necessary files that MySQL needs to run. This step will also create a MySQL service for NT operating systems and place a stoplight icon in the system tray indicating MySQL’s status. Be sure to remember your MySQL username and password that is entered here.
32
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Running MySQL ServerRunning MySQL Server
On winNT, windows 2000 or windows XP., you can start and stop them MySQL server as a service. By default the MySQL server is configured to start as a service Immediately upon boot up.
33
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Running MySQL ServerRunning MySQL Server
Various flavors of MySQL server are Various flavors of MySQL server are available for windows. If you are running available for windows. If you are running NTNT\\20002000\\XP then you should run XP then you should run mysqlmysql--maxmax--ntnt version.version.You can start and stop the server from the You can start and stop the server from the command line. See MySQL online command line. See MySQL online documentation for details.documentation for details.
34
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Installing the Application DriverInstalling the Application DriverMySQL Connector/ODBCMySQL Connector/ODBC (also known as (also known as MyODBCMyODBC) allows you to connect to a MySQL ) allows you to connect to a MySQL database server using the ODBC database API database server using the ODBC database API on all Microsoft Windows and most Unix on all Microsoft Windows and most Unix platforms.platforms.This can be downloaded from the same source This can be downloaded from the same source as the MySQL Server.as the MySQL Server.This is required to allow LabVIEW to This is required to allow LabVIEW to communicate with the MySQL server using the communicate with the MySQL server using the standard Microsoft ADO Interface.standard Microsoft ADO Interface.
35
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Installing the Application DriverInstalling the Application Driver
After installation you will see After installation you will see MyODBCMyODBClisted in your Data Source Selector.listed in your Data Source Selector.
36
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Installing the Application DriverInstalling the Application Driver
37
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Using MySQL Control CenterUsing MySQL Control Center
The MySQL Control Center is a Windows The MySQL Control Center is a Windows Based GUI application that allows you to Based GUI application that allows you to easily create databases, manipulate tables easily create databases, manipulate tables and perform SQL queries.and perform SQL queries.This tool can be used to test and debug This tool can be used to test and debug your database and perform simple your database and perform simple verification tests.verification tests.
38
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Using MySQL Control CenterUsing MySQL Control Center
39
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Using MySQL Control CenterUsing MySQL Control Center
Tables can be Tables can be created with the created with the interface and interface and Primary keys Primary keys can be defined.can be defined.
40
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
LabVIEW code AvailableLabVIEW code Available
Database Connectivity Toolkit from Database Connectivity Toolkit from National Instruments contains preNational Instruments contains pre--built built VI’s that allow simple interfaces to any VI’s that allow simple interfaces to any kind of ADO compliant database.kind of ADO compliant database.
41
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Create Table with LVDCTCreate Table with LVDCT
42
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Using ActiveX ADOUsing ActiveX ADO
If you want to use plain SQL query If you want to use plain SQL query language to interface with your MySQL language to interface with your MySQL database then you can use the ActiveX database then you can use the ActiveX component called ADO.component called ADO.This is a high level interface to all This is a high level interface to all compliant databases on Windows.compliant databases on Windows.This can be created using an automation This can be created using an automation reference.reference.
43
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
What is SQL? What is SQL? SQL is an abbreviation for “structured query SQL is an abbreviation for “structured query language” . This is the language used to language” . This is the language used to communicate with relational database systems.communicate with relational database systems.SQL was created at an IBM research center in SQL was created at an IBM research center in the 70s and was first used by Oracle in 1979.the 70s and was first used by Oracle in 1979.SQL is now an industry standard is now more SQL is now an industry standard is now more commonly referred to as ANSI SQLcommonly referred to as ANSI SQLQueriesQueries are commands, written in SQL, that you are commands, written in SQL, that you send to your RDBMS to create databases and send to your RDBMS to create databases and tables, add and modify records, delete records, tables, add and modify records, delete records, or extract information to be used in your or extract information to be used in your application. application.
44
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Using ActiveX ADOUsing ActiveX ADO
45
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Create Table with ActiveX ADOCreate Table with ActiveX ADO
46
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
LabSQL ADO VI’sLabSQL ADO VI’s
These are VI’s These are VI’s available under the available under the GNU Lesser Public GNU Lesser Public License from License from jeffreytravis.comjeffreytravis.comCan connect to Can connect to any database any database including MySQLincluding MySQL
47
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
SQL SyntaxSQL Syntax
Inserting Data:Inserting Data:–– INSERT INTO test3 INSERT INTO test3
((TestDate,TestDescription,TestStatusTestDate,TestDescription,TestStatus, , DUT_ID, DUT_ID, OperatorIDOperatorID) VALUES ) VALUES (1,'HelloWorld',1,1,1);(1,'HelloWorld',1,1,1);
Selecting Data:Selecting Data:–– SELECT * FROM Test3 WHERE SELECT * FROM Test3 WHERE TestIDTestID < 30;< 30;
48
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Working with Relational DatabasesWorking with Relational Databases
Working with relational databases requires Working with relational databases requires manipulation of multiple tables.manipulation of multiple tables.Before a data record can be inserted into Before a data record can be inserted into the Tests table we must locate the the Tests table we must locate the OperatorIDOperatorID and the DUT_ID.and the DUT_ID.After the Tests Table has been updated, After the Tests Table has been updated, we must then update the we must then update the Test_SuppliesTest_SuppliesTable.Table.
49
mmWave Integrated SolutionsmmWave Integrated Solutions Presenter: Michael AivaliotisPresenter: Michael Aivaliotis
Beyond the PresentationBeyond the Presentation
Information is available from thousands of Information is available from thousands of resources on the internet.resources on the internet.MySQL and SQL query language is a MySQL and SQL query language is a mature topic that has many books written mature topic that has many books written on the subject.on the subject.Suggestion: Buy two books:Suggestion: Buy two books:–– Any Database Design bookAny Database Design book–– Any MySQL bookAny MySQL book