Mysql

28
MY SQL MySQL is a relational database management system.The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL is owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Sun Microsystems, a subsidiary of Oracle Corporation

description

 

Transcript of Mysql

Page 1: Mysql

MY SQL

MySQL is a relational database management system.The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL is owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Sun Microsystems, a subsidiary of Oracle Corporation

Page 2: Mysql

Features A broad subset of ANSI SQL 99, as well as extensions Cross-platform support Stored procedures Triggers Cursors Updatable Views True Varchar support SSL support Query caching Sub-SELECTs (i.e. nested SELECTs) Full-text indexing and searching using MyISAM engine Embedded database library Hot backup (via mysqlhotcopy) under certain conditions

Page 3: Mysql

Management and Graphical Frontends

MySQL is primarily an RDBMS and therefore ships with no GUI tools to administer MySQL databases or manage data contained within. Users may use the included command-line tools, or download MySQL frontends from various parties that have developed desktop software and web applications to manage MySQL databases, build database structure, and work with data reco

Page 4: Mysql

MySQL can be built and installed manually from source code, but this can be tedious so it is more commonly installed from a binary package unless special customizations are required. On most Linux distributions the package management system can download and install MySQL with minimal effort, though further configuration is often required to adjust security and optimization settings.

It is still most commonly used in small to medium scale single-server deployments, either as a component in a LAMP based web application or as a standalone database server. Much of MySQL's appeal originates in its relative simplicity and ease of use, which is enabled by an ecosystem of open source tools such as phpMyAdmin.

USAGE:

Page 5: Mysql

MYSQL IN SYSTEM:

Inorder to use the mysql we again need the web server package called 'XAMPP'

“Xampp is a free and open source cross-platform web server package, consisting mainly of the Apache HTTP Server, MySQL database, and interpreters for scripts written in the PHP and Perl programming languages.”

XAMPP requires only one zip, tar or exe file to be downloaded and run, and little or no configuration of the various components that make up the web server is required. XAMPP is regularly updated to incorporate the latest releases of Apache/MySQL/PHP and Perl.

Page 6: Mysql

INSTALLATION PROCEDURE

Step 1: We need to have the xampp for linux inorder the run applications

so(as per step 1) ,download the xampp for linux with any favourable version on to the computer

Page 7: Mysql

Step 2: After the successful downloading,we need to extract the 'tar' file on to the system,select a path and just extract them using the following

commands

gunzip -d httpd-2_0_NN.tar.gz tar xvf httpd-2_0_NN.tar

*NN -refers to the current xampp versions

Page 8: Mysql

CONFIGURATION

Page 9: Mysql

Inorder to configure the ,we need to locate the xampp folder to which it is extracted.

After the location of these file we can find the configure file in the 'etc' folder as “my.cnf”,inside which we can find the

configuration file

“configuration file main Apache HTTP server configuration . It contains the

configuration directives that give the server its instructions”

Page 10: Mysql

In this file, you can use all long options that a program supports. If you want to know which options a program supports, run the program with the "--help" option.

Here follows entries for some specific programs# The MySQL server[mysqld]port = 3306socket = /opt/lampp/var/mysql/mysql.sockskip-lockingkey_buffer = 16Mmax_allowed_packet = 1Mtable_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8M

Page 11: Mysql

To know where all the plugins will be ,then;plugin_dir = /opt/lampp/lib/mysql/plugin/------------------------------------------------------------------

We should never prefer tcp/Ip ports,because it will creating a security enhancement,so if all the ports are after a same host then wen need to use the “named pipes” , in windows enabling this will make mysql useless

Page 12: Mysql

Replication Master Server (default) binary logging is required for replication log-bin deactivated by default since XAMP 1.4.11

log-bin=mysql-bin

required unique id between 1 and 2^32 - 1defaults to 1 if master-host is not set but will not function as a master if omitted

server-id = 1

Replication of master

Page 13: Mysql

IMPORTING SQL:

Any relational database can be imported into the xampp tool for furthur,this can be done using the “import” and we need to browse the '.sql' which is to be imported,after selecting it then click on the “go” button and the sql will be imported

Page 14: Mysql

EXPORTING SQL:

At fist we need to open the xampp for the database query,then after creating the table and inserting the values into the database,[which can be done either in the simplified or ordinary method like writing the sql query by ourself],then clicking the “EXPORT” we can save the sql in its format and which can be used in furthur endaveour.

Page 15: Mysql

SQL QUERIES

Page 16: Mysql

CREATE : To create an empty database named "employees" on your DBMS.

SYNTAX:CREATE TABLE personal_info (first_name char(20) not null, last_name char(20) not null, employee_id int not null)

n our example, the table contains three attributes: first_name, last_name and employee_id

DDL COMMANDS:

Page 17: Mysql

USE COMMAND:

The USE command allows you to specify the database you wish to work with within your DBMS. For example, if we're currently working in the sales database and want to issue some commands that will affect the employees database, we would preface them with the following SQL command:

USE employees

It's important to always be conscious of the database you are working in before issuing SQL commands that manipulate data.

Page 18: Mysql

ALTER :Once you've created a table within a database, you may wish

to modify the definition of it. The ALTER command allows you to make changes to the structure of a table without deleting and recreating it. Take a look at the following command:

ALTER TABLE personal_infoADD salary money null

This example adds a new attribute to the personal_info table -- an employee's salary. The "money" argument specifies that an employee's salary will be stored using a dollars and cents format. Finally, the "null" keyword tells the database that it's OK for this field to contain no value for any given employee.

Page 19: Mysql

DROP :

The final command of the Data Definition Language, DROP, allows us to remove entire database objects from our DBMS. For example, if we want to permanently remove the personal_info table that we created, we'd use the following command:

DROP TABLE personal_info

Page 20: Mysql

INSERT :

The INSERT command in SQL is used to add records to an existing table. Returning to the personal_info example from the previous section, let's imagine that our HR department needs to add a new employee to their database. They could use a command similar to the one shown below:

INSERT INTO personal_infovalues('bart','simpson',12345,$45000)

Page 21: Mysql

SELECT :

The SELECT command is the most commonly used command in SQL. It allows database users to retrieve the specific information they desire from an operational database. Let's take a look at a few examples, again using the personal_info table from our employees database

SELECT * from personal_info

Page 22: Mysql

UPDATE :

The UPDATE command can be used to modify information contained within a table, either in bulk or individually.

UPDATE personal_infoSET salary = salary * 1.03

Page 23: Mysql

DELETE :

The DELETE command with a WHERE clause can be used to remove his record from the personal_info table:

DELETE FROM personal_infoWHERE employee_id = 12345

Page 24: Mysql

DML COMMANDS:

Group By:The Group By statement in SQL is used for aggregation,

which means that the result that is returned is based on grouping of results based on a column aggregation.

SELECT Roll_No, SUM(Marks) FROM t_studentsWHERE Class = 5GROUP BY Roll_No

Page 25: Mysql

Order By:

The Order By clause in SQL is used to set the sequence of the output in terms of being alphabetical, magnitude of size, order of date. It may accompanied by an 'asc' or 'desc' clause so as to specify whether the results are in ascending or descending order. Note: The results of a select query that does not use asc or desc is in ascending order, by default.

SELECT fname, lname FROM t_students ORDER BY fname ASC;

Page 26: Mysql

BETWEEN:The BETWEEN keyword allows for selecting a range. The syntax for the BETWEEN clause is as follows:

SELECT "column_name"FROM "table_name"WHERE "column_name" BETWEEN 'value1' AND 'value2'

This will select all rows whose column has a value between 'value1' and 'value2'.

UNIQUE:The UNIQUE constraint ensures that all values in a column are distinct.For example, in the following CREATE TABLE statement,

CREATE TABLE Customer(SID integer Unique,Last_Name varchar (30),First_Name varchar(30));Column "SID" has a unique constraint, and hence cannot include duplicate values. Such constraint does not hold for columns "Last_Name" and "First_Name"

Page 27: Mysql

SQL has several arithematic functions, and they are:

• AVG: Average of the column.

• COUNT: Number of records.

• MAX: Maximum of the column.

• MIN: Minimum of the column.

• SUM: Sum of the column.

The syntax for using functions is,

SELECT "function type" ("column_name")FROM "table_name"

SQL FUNCTIONS:

Page 28: Mysql