Mysql introduction

Home   Contents

Introduction to MySQL

About this tutorial

This is MySQL tutorial. It covers the MySQL database, various mysql command line tools and the SQL language covered by the database engine. It is an introductory tutorial for the beginners.


MySQL database

MySQL is a leading open source database management system. It is a multi-user, multithreaded database management system. MySQL is especially popular on the web. It is one of the parts of the very popular LAMP platform. Linux, Apache, MySQL and PHP. Currently MySQL is owned by Oracle. MySQL database is available on most important OS platforms. It runs under BSD Unix, Linux, Windows or Mac. Wikipedia, YouTube, Facebook use MySQL. These sites manage millions of queries each day. MySQL comes in two versions. MySQL server system and MySQL embedded system.

The development of MySQL begun in 1994 by a Swedish company MySQL AB. Sun Microsystems acquired MySQL AB in 2008. Sun was bought by Oracle in 2010. So today, Oracle corporation is the owner of the MySQL database.

MySQL, PostgreSQL, Firebird, SQLite, Derby and HSQLDB are the most well known open source database systems.

MySQL is developed in C/C++. Except of the C/C++, APIs exist for PHP, Python, Java, C#, Eiffel, Ruby, Tcl or Perl.

Definitions

relational database is a collection of data organized in tables. There are relations among the tables. The tables are formally described. They consist of rows and columns. SQL (Structured Query Language) is a database computer language designed for managing data in relational database management systems. A table is a set of values that is organized using a model of vertical columns and horizontal rows. The columns are identified by their names. A schema of a database system is its structure described in a formal language. It defines the tables, the fields, relationships, views, indexes, procedures, functions, queues, triggers and other elements. A database row represents a single, implicitly structured data item in a table. It is also called a tuple or a record. A column is a set of data values of a particular simple type, one for each row of the table. The columns provide the structure according to which the rows are composed. A field is a single item that exists at the intersection between one row and one column. A primary key uniquely identifies each record in the table. A foreign key is a referential constraint between two tables. The foreign key identifies a column or a set of columns in one (referencing) table that refers to a column or set of columns in another (referenced) table. A trigger is a procedural code that is automatically executed in response to certain events on a particular table in a database. A view is a specific look on data in from one or more tables. It can arrange data in some specific order, highlight or hide some data. A view consists of a stored query accessible as a virtual table composed of the result set of a query. Unlike ordinary tables a view does not form part of the physical schema. It is a dynamic, virtual table computed or collated from data in the database. A transaction is an atomic unit of database operations against the data in one or more databases. The effects of all the SQL statements in a transaction can be either all committed to the database or all rolled back. An SQL result set is a set of rows from a database, returned by the SELECT statement. It also contains meta-information about the query such as the column names, and the types and sizes of each column as well. An indexis a data structure that improves the speed of data retrieval operations on a database table.

Tables used

Here we will list all the tables, that are used throughout the tutorial.

-- SQL for the Cars table

USE mydb;
CREATE TABLE IF NOT EXISTS Cars(Id INTEGER PRIMARY KEY, Name VARCHAR(50), 
Cost INTEGER);
INSERT INTO Cars VALUES(1,'Audi',52642);
INSERT INTO Cars VALUES(2,'Mercedes',57127);
INSERT INTO Cars VALUES(3,'Skoda',9000);
INSERT INTO Cars VALUES(4,'Volvo',29000);
INSERT INTO Cars VALUES(5,'Bentley',350000);
INSERT INTO Cars VALUES(6,'Citroen',21000);
INSERT INTO Cars VALUES(7,'Hummer',41400);
INSERT INTO Cars VALUES(8,'Volkswagen',21600);

Cars table.

-- SQL for the Customers, Reservations tables

USE mydb;

CREATE TABLE IF NOT EXISTS Customers(CustomerId INTEGER AUTO_INCREMENT 
    PRIMARY KEY, Name VARCHAR(55));
INSERT INTO Customers(Name) VALUES('Paul Novak');
INSERT INTO Customers(Name) VALUES('Terry Neils');
INSERT INTO Customers(Name) VALUES('Jack Fonda');
INSERT INTO Customers(Name) VALUES('Tom Willis');

CREATE TABLE IF NOT EXISTS Reservations(Id INTEGER AUTO_INCREMENT
    PRIMARY KEY, CustomerId INTEGER, Day DATE);
INSERT INTO Reservations(CustomerId, Day) VALUES(1, '2009-11-22');
INSERT INTO Reservations(CustomerId, Day) VALUES(2, '2009-11-28');
INSERT INTO Reservations(CustomerId, Day) VALUES(2, '2009-11-29');
INSERT INTO Reservations(CustomerId, Day) VALUES(1, '2009-11-29');
INSERT INTO Reservations(CustomerId, Day) VALUES(3, '2009-12-2');

Customers and Reservations.

-- SQL for the Books table

USE mydb;

CREATE TABLE IF NOT EXISTS Books(Id INTEGER PRIMARY KEY, 
    Title VARCHAR(100), Author VARCHAR(60));
INSERT INTO Books VALUES(1,'War and Peace','Leo Tolstoy');
INSERT INTO Books VALUES(2,'The Brothers Karamazov','Fyodor Dostoyevsky');
INSERT INTO Books VALUES(3,'Paradise Lost','John Milton');
INSERT INTO Books VALUES(4,'Crime and Punishment','Fyodor Dostoyevsky');
INSERT INTO Books VALUES(5,'Cousin Bette','Honore de Balzac');

Books.

Sources

Home ‡  Contents ‡  Top of Page

转载于:https://www.cnblogs.com/threef/p/3271850.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
About the Author Joel Murach has been writing and editing books about computer programming for over 10 years. During that time, he has written extensively on a wide range of Java, .NET, web, and database technologies. When he's not programming or writing books about programming, he can be found surfing or writing music. "If you ever wanted to learn to use MySQL, write SQL queries, create database elements, then this is the book to pick up." (JavaRanch.com) "I was amazed at how much information was packed into this book." "As a developer with almost 10 years of MySQL experience, I still picked up a lot of new detail on things I thought I knew." "I found this to be a great introductory book to MySQL." "Has already proven to be helpful in solving several challenges I've encountered on my current MySQL project." That's a sampling of what developers said about the 1st Edition of Murach's MySQL. Now, this 2nd Edition has been updated and improved throughout. As a result, it's easier than ever to use for learning MySQL from scratch, for switching to MySQL from another flavor of SQL (like MS SQL Server or Oracle), or for quickly looking up the forgotten details that are so essential as you develop database applications. Section 1 introduces you to relational databases and SQL, shows you how to use the graphical MySQL Workbench to work with a MySQL database, and teaches you to code SQL queries to retrieve, add, update, and delete data in a MySQL database. Section 2 goes deeper into querying, showing you how to work with summary queries, subqueries, data types, and functions. Section 3 shows you how to design a MySQL database using an EER model, implement the design, and create views. Section 4 shows how to create stored procedures that provide functionality similar to procedural programming languages like PHP, Java, C++, C#, and VB. And Section 5 introduces you to database administration tasks like securing and backing up database data. Whether you start from the beginning or jump in anywhere, it's a great guide for MySQL users at any level.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值