Professional Documents
Culture Documents
Unit 1 Final PDF
Unit 1 Final PDF
1.1 Introduction
MySQL, the most popular Open Source SQL database management
system, is developed, distributed, and supported by MySQL AB. MySQL AB
is a commercial company, founded by the MySQL developers. It is a second
generation Open Source company that unites Open Source values and
methodology with a successful business model.
The MySQL Web site (http://www.mysql.com/) provides the latest
information about MySQL software and MySQL AB.
MySQL is a Database Management System
A database is a structured collection of data. It may be anything from a
simple shopping list to a picture gallery or the vast amounts of
information in a corporate network. To add, access, and process data
stored in a computer database, you need a database management
system such as MySQL Server.
MySQL is a Relational Database Management System
A Relational Database stores data in separate tables rather than putting
all the data in one big storeroom. This adds speed and flexibility.
MySQL software is Open Source
Open Source means that it is possible for anyone to use and modify the
software. Anybody can download the MySQL software from the Internet
and use it without paying anything. If you wish, you may study the
Objectives
After studying this unit, you should be able to:
explain the features of MySQL
describe the process of connecting to and disconnecting from MySQL
server
explain the operations of accessing and creating databases and tables
using MySQL
discuss the steps in Loading data from external data sources
Full support for SQL GROUP BY and ORDER BY clauses. Support for
group functions (COUNT(), COUNT(DISTINCT ...), AVG(), STD(),
SUM(), MAX(), MIN(), and GROUP_CONCAT()).
Support for LEFT OUTER JOIN and RIGHT OUTER JOIN with both
standard SQL and ODBC syntax.
Support for aliases on tables and columns as required by standard SQL.
DELETE, INSERT, REPLACE, and UPDATE return the number of rows
that were changed (affected). It is possible to return the number of rows
matched instead by setting a flag when connecting to the server.
The MySQL-specific SHOW statement can be used to retrieve
information about databases, storage engines, tables, and indexes.
MySQL 5.0 adds support for the INFORMATION_SCHEMA database,
implemented according to standard SQL.
The EXPLAIN statement can be used to determine how the optimizer
resolves a query.
Function names do not clash with table or column names. For example,
ABS is a valid column name. The only restriction is that for a function
call, no spaces are allowed between the function name and the “(” that
follows it.
You can refer to tables from different databases in the same statement.
Security:
A privilege and password system that is very flexible and secure, and
that allows host-based verification.
Passwords are secure because all password traffic is encrypted when
you connect to a server.
index width is 1000 bytes (767 for InnoDB); before MySQL 4.1.2, the
limit is 500 bytes. An index may use a prefix of a column for CHAR,
VARCHAR, BLOB, or TEXT column types.
Connectivity:
Clients can connect to MySQL Server using several protocols:
Clients can connect using TCP/IP sockets on any platform.
On Windows systems in the NT family (NT, 2000, XP, 2003, or
Vista), clients can connect using named pipes if the server is started
with the – enable-named-pipe option. In MySQL 4.1 and higher,
Windows servers also support shared-memory connections if started
with the – shared-memory option. Clients can connect through
shared memory by using the – protocol=memory option.
On Unix systems, clients can connect using Unix domain socket
files.
MySQL client programs can be written in many languages. A client
library written in C is available for clients written in C or C++, or for any
language that provides C bindings.
APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and Tcl are
available, allowing MySQL clients to be written in many languages.
The Connector/ODBC (MyODBC) interface provides MySQL support for
client programs that use ODBC (Open Database Connectivity)
connections. For example, you can use MS Access to connect to your
MySQL server. Clients can be run on Windows or Unix. MyODBC
source is available. All ODBC 2.5 functions are supported, as are many
others.
The Connector/J interface provides MySQL support for Java client
programs that use JDBC connections. Clients can be run on Windows or
Unix. Connector/J source is available.
MySQL Connector/NET enables developers to easily create .NET
applications that require secure, high-performance data connectivity with
MySQL. It implements the required ADO.NET interfaces and integrates
into ADO.NET aware tools. Developers can build applications using their
choice of .NET languages. MySQL Connector/NET is a fully managed
ADO.NET driver written in 100% pure C#.
Localization:
The server can provide error messages to clients in many languages.
Full support for several different character sets, including latin1
(cp1252), german, big5, ujis, and more. For example, the Scandinavian
characters “å”, “ä” and “ö” are allowed in table and column names.
Unicode support is available as of MySQL 4.1.
All data is saved in the chosen character set.
Sorting and comparisons are done according to the chosen character
set and collation (using latin1 and Swedish collation by default). It is
possible to change this when the MySQL server is started. To see an
example of very advanced sorting, look at the Czech sorting code.
MySQL Server supports many different character sets that can be
specified at compile time and runtime.
As of MySQL 4.1, the server time zone can be changed dynamically,
and individual clients can specify their own time zone.
Clients and Tools:
MySQL AB provides several client and utility programs. These include
both command-line programs such as mysqldump and mysqladmin,
and graphical programs such as MySQL Administrator and MySQL
Query Browser.
MySQL Server has built-in support for SQL statements to check,
optimize, and repair tables. These statements are available from the
command line through the mysqlcheck client. MySQL also includes
myisamchk, a very fast command-line utility for performing these
operations on MyISAM tables.
MySQL programs can be invoked with the --help or -? option to obtain
online assistance.
and time. Conceptually, this is similar to the idea of the Unix crontab
(also known as a “cron job”) or the Windows Task Scheduler.
Server Log Tables. Before MySQL 5.1, the server writes general query
log and slow query log entries to log files. As of MySQL 5.1, the server's
logging capabilities for these logs are more flexible. Log entries can be
written to log files (as before) or to the general_log and slow_log tables
in the mysql database. If logging is enabled, either or both destinations
can be selected. The --log-output option controls the destination or
destinations of log output.
Upgrade Program. The mysql_upgrade program (available as of
MySQL 5.1.7) checks all existing tables for incompatibilities with the
current version of MySQL Server and repairs them if necessary. This
program should be run for each MySQL upgrade.
MySQL Cluster. MySQL Cluster is now released as a separate
product, based on MySQL 5.1 but with the addition of the
NDBCLUSTER storage engine. Clustering support is longer available in
mainline MySQL 5.1 releases. MySQL Cluster releases are identified by
a 3-part NDB version number; currently, the MySQL Cluster NDB 6.2
and MySQL Cluster NDB 6.3 release series are available for production
use.
host and user represent the host name where your MySQL server is
running and the user name of your MySQL account. Substitute appropriate
values for your setup. The ******** represents your password; enter it when
mysql displays the Enter password: prompt.
If that works, you should see some introductory information followed by a
mysql> prompt:
The mysql> prompt tells you that mysql is ready for you to enter
commands.
If you are logging in on the same machine that MySQL is running on, you
can omit the host, and simply use the following:
If, when you attempt to log in, you get an error message such as ERROR
2002 (HY000): Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2), it means that that MySQL server daemon (Unix) or
service (Windows) is not running. Consult the administrator
Some MySQL installations allow users to connect as the anonymous
(unnamed) user to the server running on the local host. If this is the case on
your machine, you should be able to connect to that server by invoking
mysql without any options:
shell> mysql
After you have connected successfully, you can disconnect any time by
typing QUIT (or \q) at the mysql> prompt:
mysql> QUIT
Bye
Most examples in the following sections assume that you are connected to
the server. They indicate this by the mysql> prompt.
The following screen shot shows the appearance of mysql> prompt after the
user types in the correct password.
The following screen shot shows an error message wherein the user tries to
access a table without using any database; i.e. as s first step, the user must
select a database already present by using the USE <DATABASE-NAME>
command and then access the tables, views or any other data structures
within the database.
Other wise the error message “Error 1046: No database Selected” would be
generated by the database server.
The screen shot below shows the command Create Database <Database-
Name> used to create a database by the user.
After successful execution of the above command, the user can type in the
Show Databases command to find out the successful creation of the
database created by him / her. Then the user can start creating his data
objects like tables inside the database.
The following screenshot shows how the user can select his own database
created in the previous step and start creating tables using Create Table
command. The DESC command can be used to show the metadata
regarding the table created.
Step – 1: Opening a Notepad file from the Start menu of the Windows OS
Step – 2: The data should be tab separated and the number of columns
correpsond to the number of columns of the base table. The data typed in
the notepad file should correspond to the data type set in the underlying
table.
Step – 4: Creation of the underlying base table to which the data values
should be populated from the notepad file created in the C drive of your hard
disk.
In this process we use the “LOAD DATA INFILE C:\FileName.txt”
command which enables us to load the data into the specified database
table.
1.8 Summary
This unit has covered the following topics:
1. Features of MySQL: Some of the major features discussed here are
Internals and Portability, Data Type support, Security Issues, etc.
2. Top Reasons for using MySQL: The top 10 reasons for using MySQL
by majority of the user community are discussed here like Scalability &
Flexibility, High Performance, Robust Transactional support, Web and
Data Warehouse strengths, Stronger data protection, etc.
3. MySQL Development Roadmap: This topic provides an overview
about features that have been implemented in previous series and that
are new in this current release series (5.1), and an overview about
upcoming additions or changes in the next release series (6.0).
4. Connecting to and Disconnecting from the Server: This section
discusses about the syntax used to connect to the database server and
disconnect from the database server using command line interface.
5. Accessing and Creating Databases and Tables: This topic discusses
various methods and functions used to access and create databases
and tables within the MySQL server database.
6. Loading Data: This topic discusses about the methods of loading data
into the MySQL database tables from external files such as notepad
data.
1.10 Answers
Self Assessment Questions
1. Relational Database Management System
2. Security
3. 64
Terminal Questions
1. 1. Portability
2. Fast Thread based Memory Allocation System
3. Full operator and Functional Support
4. Support for Group By and Order By Clauses
(Refer to section 1.2)
Sikkim Manipal University Page No. 22
RDBMS with MySQL Unit 1