You are on page 1of 193

1

www.kaniyam.com

MySQL
( Free Open Source Software ) Database System.
, .
"" ,
2012 . MySQL
,
.
, editor@kaniyam.com
.
http://kaniyam.com/mysql-book-in-tamil
. .
, .
.

editor@kaniyam.com

www.kaniyam.com

MySQL
2013
2013 .

:
:

. ,

, , www.kaniyam.com
. .
.

:
http://dev.kaniyam.com/projects/kaniyam/files

www.kaniyam.com

www.kaniyam.com

"" [ http://kaniyam.com ] MySQL-


.
.
.
.
,
.
.
,
.
.

.
,

11 2013

: nithyadurai87@gmail.com
: http://nithyashrinivasan.wordpress.com

www.kaniyam.com

1 MySQL - ......................................................................................................................... 11
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8

MySQL - ........................................................................................................... 11
MySQL- install ............................................................................................................. 13
Ubuntu Linux- MySQL- install ................................................................................14
Configuration................................................................................................................................ 15
Query cache.................................................................................................................................. 16
MySQL clients............................................................................................................................... 17
CENTOS/RHEL - ........................................................................................................ 18
Windows- MySQL- install ........................................................................................ 18

2 SQL Command line client- ...................................................................................30


2.1 Client Server- ..................................................................30
2.2 Client server- ..........................................................32
2.3 Batch mode- client- .................................................................................33
2.4 Client- Command line- ..............................................................................33
2.5 Option file- Connection Defaults- ...................................................................34
2.6 MySQL- ........................................................................................................ 35
2.7 Text editor commands- .......................................................................36
2.8 Command-line- Tab- ..........................................................................................37
2.9 Command-line history- ..............................................................................37
2.10 Tools........................................................................................................... 38
3 Databases ............................................................................................................... 40
3.1
3.2
3.3
3.4
3.5

database- server- .........................................................................40


Database- ..........................................................................................42
database- server- :..................................................................................42
USE Command- ...................................................................................................... 43
LIKE Operator - ....................................................................................................... 44

4 Tables ...................................................................................................................... 46
4.1
4.2
4.3
4.4

Table ..................................................................................................................... 46
database- table- .....................................................................................49
database- table- ...................................................51
database- table- Copy ....................................................................52

www.kaniyam.com

7
4.5 Tables- database- ........................................53
4.6 database- table - .................................................................54
4.7 Tables - ................................................................................................ 55

5 Columns - ............................................................................................................................ 57
5.1 column- table- .................................................................................57
5.2 Column- ......................................................................................58
5.3 column- table- .....................................................................................59

6 Indexes - ............................................................................................................................. 61
6.1
6.2
6.3
6.4

Index- table- ............................................................................................61


Index- .......................................................................................... 62
Index- ......................................................................................................................... 62
Identifiers ......................................................................................................... 63

7 Library ' Databases' - ..............................................................................65


7.1
7.2
7.3
7.4
7.5
7.6
7.7

Library Database- .............................................................................................65


tables- ................................................67
Book table- .........................................................................69
Data Types:................................................................................................................................... 71
Column Names: ........................................................................................................................... 72
Person table- .....................................................................73
loan table- ............................................................................74

8 Library Database- data- ...............................................................77


8.1
8.2
8.3
8.4
8.5
8.6
8.7
8.8

book table- data- ................................................................................78


Auto increment column- data- ..........................................................................80
Person table- data- ..............................................................................83
file- queries data- table- ..............................................84
table- data- table- insert ..............................................87
file- data- table- .....................................................88
loan table- data- insert .............................................................................91
Function date- insert .......................................................................................98

www.kaniyam.com

8
9 Library Database- data- ...................................................100
9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8
9.9

Limit Clause- ......................................................................................................... 100


Order by result- ............................................................................101
DISTINCT data- .................103
data- 'like' ..................................104
Aggregate functions data- ................................106
Date functions ................................................107
Decimal columns .....................................110
NULL- ...................................................................................................................... 111
Query result- file- ...............................................................................112

10 Library database- Tables- ...................................................116


10.1 ................................................................................................... 116
10.2 Where clause tables- ............................................................................117
10.3 Join keyword tables- .............................................................................119
10.4 Inner join tables- ....................................................................................120
10.5 Table aliases- ............................................................................................121
10.6 Outer Join tables- ...................................................................................122
10.7 Column alias- ...........................................................................................124
10.8 Subquery tables- ...................................................................................125
10.9 Non-correlated subquery ...........................................................................126
10.10 Select statement- Subquery- ..........................................................129
10.11 Correlated subquery ..................................................................................130
10.12 Union queries- .....................................................................................131

11 Library database- data- ...........................................134


11.1 Function column- ..................................................136

12 Library database- data- .............................................138


12.1 tables- rows- .....................................................................138
12.2 ............................................................................................................ 139

13 Users- ....................................................................................................................... 143


13.1 Server- user- .........................................................143
13.2 user- server- ..............................................................145
13.3 user- ......................................................................................146

www.kaniyam.com

9
13.4 Wildcards- IP address- users- ............148
13.5 database/table- ..................................149
13.6 Password - ............................................................................................................. 150
13.7 Users- tables- privileges- .......................151
13.8 User privileges ..........................153
13.9 User- privileges- ....................................................................153
13.10 user- .................................................................................155
13.11 Network access- ...............................................................................156
13.12 User authentication- ......................................................................156
13.13 SSL - ..........................................................157

14 MySQL- Application Programming Interface - API.................................................................159


14.1 C API.........................................................................................................159
14.2 MySQL- .......................................................................................................... 160
14.3 Query- execute ................................................................................................... 161
14.4 Result set- ..............................................................................162
14.5 Error Messages- .....................................................................................163
14.6 ................................................................................................................164
14.7 Perl API....................................................................................................166
14.8 MySQL- ........................................................................................ 167
14.9 Query- execute ................................................................................................... 167
14.10 Result set- ...........................................................................168
14.11 Error Messages- ...................................................................................168
14.12 ............................................................................................................ 169
14.13 PHP API..................................................................................................170
14.14 MySQL- ...................................................................................................... 170
14.15 Query- execute ................................................................................................. 171
14.16 Result set- ...........................................................................171
14.17 Error Messages- ...................................................................................172
14.18 ............................................................................................................ 173

15 Backup Trouble Shooting .....................................................................175


15.1
15.2
15.3
15.4
15.5
15.6
15.7

Backup ........................................................................................................................ 175


Full Backup ................................................................................................................. 175
Incremental backup .................................................................................................. 177
Backup- restore ........................................................................................................179
Full backup- restore ............................................................................................... 179
Incremental Backup- restore ...............................................................................179
Table- corrupt- data- .................................................180

www.kaniyam.com

10
15.8 Server Crash- .................................................................................................182
15.9 ERRORS ................................................................................................184
Can't Connect to MySQL Server................................................................................................ 184
Access Denied.............................................................................................................................. 186
Too Many Connections................................................................................................................ 186
MySQL Server Has Gone Away.................................................................................................. 187
Got Error from Table Handler..................................................................................................... 188
15.10 ......................................................................................................................188

16 ................................................................................................................................... 190
........................................................................................................................................... 190
............................................................................................................................................ 190
................................................................................................................................. 191
............................................................................................................................ 192

www.kaniyam.com

11

1 MySQL -
Database data- ,
. SQL(Structured
Query Language) database- data-
. RDBMS , database-
data-
Management software
.

MySQL RDBMS Software . SQL


PHP, PERL, C, C++, JAVA
. free software GPL
General Public License- .
Internet- download
.

1.1 MySQL -

MySQL- .
MySQL server MySQL client
. MySQL client
front end tool . Windows- console
prompt GNU/Linux-- shell prompt ,
SQL commands . commands- MySQL
server . MySQL
server-
. MySQL server-
result- .

www.kaniyam.com

12

MySQL clients MySQL Server


.
MySQL client- .
Password Authentication
SQL Queries server- Tokens
Tokens- Server-
Compress Encrypt

Server-

www.kaniyam.com

13

MySQL server client request-


response- . Management Layer Storage Engine
.
memory, disk network- .
Management Layer , MySQL client request-
, .
decrypt decode
Queries parse
Query Cache - catched queries -
Storage Engine-
disk- logs- memory- logs-
.
Storage Engine databases, tables, indexes - .
logs .
data- disk memory- .
Network MySQL server-
.
1.2 MySQL- install
MySQL- install ,
.

MySQL- install .
MySQL- machine- install .
.
BSD,LinuX, Mac OS X, Solaris windows
platform- MySQL- install
.

www.kaniyam.com

14

MySQL server- permissions-


account . MySQL- install
root account
permissions- .

MySQL client . MySQL command-line


MySQL query browser .
MySQL
command-line- .

1.3 Ubuntu Linux- MySQL- install

12.10- MySQL .
debian ubuntu Linux Mint distribution- .
Terminal- .
sudoaptgetinstallmysqlservermysqlclient
MySQL- repository-
download install . MySQL- root
user- password . password
.
MySQL- .
sudomysql_secure_installation
.
1. Anonymous users-

www.kaniyam.com

15

2. localhost- root-
3. test database-

By default, a MySQL installation has an anonymous user, allowing anyone


to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

MySQL- .
1.4 Configuration
MySQL- configuration options- .
/etc/mysql directory- MySQL- config directory .

www.kaniyam.com

16

/etc/mysql/my.cnf
file MySQL- configuration options- .
Log file, port number, ip binding, performance options .
options .
port=3306
MySQL server- 3306 port- .
user=mysql
mysql user , user- server .
server- .
datadir=/var/lib/mysql
MySQL- database folder- . Backup
, folder- backup .
bindaddress=127.0.0.1
ip address- MySQL server .
log_error=/var/log/mysql/error.log
Configuration connection- file- log
.
1.5 Query cache
MySQL server- select queries-, results- cache-
. , server- .
options .
query_cache_limit=1m
query_cache_size=16m

www.kaniyam.com

17

m mb . RAM-
. .
query_cache_limit=2m
query_cache_size=32m
my.cnf file- , MySQL server- restart
.
MySQL server- restart
sudoservicemysqlrestart

MySQL server- stop


sudoservicemysqlstop

MySQL server- start


sudoservicemysqlstart

1.6 MySQL clients


Command line client GUI , MySQL-
clients .
MySQL Work Bench
sudoaptgetinstallMySQLworkbench
MySQL Navigator
sudoaptgetinstallMySQLnavigator
Emma
sudoaptgetinstallemma
MySQL Admin
www.kaniyam.com

18

sudoaptgetinstallMySQLadmin
PHPMyAdmin
sudoaptitudeinstallphpmyadmin

1.7 CENTOS/ RHEL -

Fedoro, CentOS RHEL distribution- ,


.
yuminstallmysqlmysqlserver

root- password . .
/usr/bin/mysqladminurootpassword'COMPLEXPASSWORDHERE'
password- root-
.
/usr/bin/mysqlsecureinstallation
.
1.8 Windows- MySQL- install
MySQL- (MySQL Community Server 5.5.29)
http://mysql.com/downloads - . msi
file- .
MySQL 5.1.35 -.
---

www.kaniyam.com

19

---

www.kaniyam.com

20

www.kaniyam.com

21

www.kaniyam.com

22

www.kaniyam.com

23

www.kaniyam.com

24

www.kaniyam.com

25

www.kaniyam.com

26

www.kaniyam.com

27

fire wall enable .

www.kaniyam.com

28

Port 3306- . MySQL- .

www.kaniyam.com

29

www.kaniyam.com

30

2 SQL Command line client-


MySQL- clients . GUI desktop
application, Internet web-based applications
shell text-only applications .
MySQL server- text-only command line client-
MySQL- .
tools , MySQL tool-
, tool-
.
MySQL tool- server-
tool.
.
2.1 Client Server-
MySQL-client , machine- MySQL server-
.

www.kaniyam.com

31

syntax .
shell> mysql [-h host] [-u user_name] [-p] [db_name]
optional
arguments- .

-h : host-
. , machine-
local server- .

-u : Username- . ,
UNIX username- ,
MySQL- authenticate .

-p : password- .
user account- , password
, .

www.kaniyam.com

32

Database_name : database-
. , Use
command- , database-
.

, options ,
mysql -?
shell prompt - run .
arguments- .
2.2 Client server-
mysql> prompt-
exit
type mysql-server- .

www.kaniyam.com

33

2.3 Batch mode- client-


input file queries- MySQL- , result-
output file- batch mode .
, query- MySQL-
result- .

syntax .
echo'SELECT1+1'|mysqlusome_userp
Shell commands- , MySQL- pipes input
redirection- shell commands- .
shell command , input file-
commands- read MySQL- .
MySQL, username password- authenticate
, commands- execute
output file- .
mysqluuserp<input_file>output_file

2.4 Client- Command line-


Unix,Linux Mac OS X operating system- MySQL,
GNU Readline library . command line-
www.kaniyam.com

34

tool . readline, 100-


commands- .
.

CTRL+a

CTRL+e

ALT+b .

ALT+f .

CTRL+w .

CTRL+u command-

CTRL+ l commands- ,

ALT+u uppercase- .

ALT+l lowercase-

ALT+_ .

2.5 Option file- Connection Defaults-


MySQL- ,
,
file- , file- MySQL .
options- command line-
.
MySQL- instances- options-
my.cnf file- ( MySQL- global configuration file) .
Unix operating system- user-
options- , home directory- .my.cnf file-
.

www.kaniyam.com

35

file- , file- options-


. form- .
,
file , MySQL-
options .
file- options-, command line-
options- . .

2 . --host
host .

option- . h
host .

option- equal sign


.

Comments- # - .

, mysql -? run
.
2.6 MySQL-
MySQL command-line client- ,
command function- ,
helpcommand_or_function_name
enter . command function
. 'show tables'
command- syntax
helpshowtables
enter . output- .
www.kaniyam.com

36

MySQL ,
helpcontents
type . command, MySQL server-
, .

2.7

Text editor commands-


MySQL command line- queries enter ,
queries- .
queries- , query- \e
enter- .

www.kaniyam.com

37

$EDITOR environment variable, query- edit


, editor- . query-
, file- save , editor- .
query- MySQL- load . execute .
execute , semicolon (;) \G type
enter- . edit
query- execute .

2.8 Command- line- Tab-


query- , database, tables
column- .
tab .
, MySQL
.
table- server-
, \# type enter- .
.

2.9 Command- line history-


MySQL command-line- ,
session- commands
buffer .
commands- , .
commands- run up
arrow ctrl+P .
, down arrow
www.kaniyam.com

38

ctrk+n- . query- run


enter- . , query-
run .
Command history- command-
, ctrl+r type command-
.

commands ,
ctrl+r type command

Alt+> buffer- command-


.
Alt+< buffer- command- .

2.10 Tools
MySQL Administrator MySQL query browser
tools . MySQL
AB- GUI Applications .
open source . Cross-Platform- (Linux,Mac OSX
&Windows) .
MySQL Query Browser, ad-hoc queries- ,
.

www.kaniyam.com

39

MySQL Administrator-, MySQL


server- digital dashboard- ,
productivity- .

www.kaniyam.com

40

3 Databases
Databases data- ,
container . MySQL Server
- databases .
database- .
tables - .

Databases - ,
. containers
. database -
.
3.1 database- server-
database- , server-
databases .
command .
SHOWDATABASES;
server- databases- .
install MySQL- command result -
.

www.kaniyam.com

41


database- . command .
CREATEDATABASEexams;

command, exams database-


. database .
tables . database
. Tables .
www.kaniyam.com

42

3.2 Database-
Databases . MySQL -
SQL command - .
MySQL - version -
.
1. MySQL server - .
2. Database - directory -
3. Server - .
process, MySQL - version - ,
server database - tables -
. database-
, tables-
. .
3.3 database- server- :
drop DB Command, database - table
- . command -
.
, tables - database
- .
DROPDATABASEexams;

www.kaniyam.com

43

3.4 USE Command-


MySQL install , databases - .
run query database - run
use command .
USElibrary;

www.kaniyam.com

44

database query -
. query- database-
.
SELECTtitleFROMlibrary.book;
.
SELECTtitleFROMbook;
.
3.5 LIKE Operator -
word- word
databases- Like operator -
.
SHOWDATABASESLIKE'my%';
command - install database -
run result - .

www.kaniyam.com

45

Like Operator- .
Percent(%) Underscore(_)
.
Percentage(%) - , Like Command
Percentage - 0
.
underscore(_) - , Like Command
Underscore- replace ,
.

www.kaniyam.com

46

4 Tables
database- tables .
table-
table definition - . rows columns
format- data- . table
.
4.1 Table
Address
.
Address , ,
.
index tab,

.
.

www.kaniyam.com

47

table -
. (
) columns ,
( ) rows table -
.

index- , table -
column- index
. .

www.kaniyam.com

48

MySQL Table- :
Table data- .
Table Body - row data- .
Table definition - row- data
Columns- .
Column - Name(eg: book_id) Type(eg:
Integer)- . Type-
. data
. Column, Integer
, 1
6502 3.14
.
row- Column-
. Column-
. Book_id
Column, SMALLINT Type- ,
data row- .
tables- Relation- Columns-
table- degree .

www.kaniyam.com

49

tables- Relation- rows-


table- cardinality .
Table - , database -
. Table - ,
(E.g: column - default collation
, table - terabytes of data
) options .
Tables - ,
phrases - .
4.2 database- table-

1. table- , database- tables


.
command .
USEexams;
USE command, 'exams' database- .
queries database- execute
.
2. database- tables
command- execute .
SHOWTABLES;
database- tables- .

table- .
3. tables - 2
. tables - syntax
www.kaniyam.com

50

elements- .
tables - process
.
table - code .
CREATETABLEmarksheet(
student_idINT,
nameVARCHAR(255)NOTNULL,
marksINT
);
code - .

www.kaniyam.com

51

4. Table- , ,
command- run .
DESCmarksheet;
DESCRIBEmarksheet;
table- .
4.3 database- table-
'marksheet' table- 'marks' ,
rename table command- .
RENAMETABLEmarksheetTOmarks;

www.kaniyam.com

52

marksheet table- marks


.

4.4 database- table- Copy


create table commnad, 'marksheet' table-
'marks' table- .
insert command, 'marksheet' table-
'marks' table- .

CREATETABLEnew_tableLIKEold_table;
INSERTnew_tableSELECT*FROMold_table;

www.kaniyam.com

53

queries - ,
table - ( indexes table options
) copy .
4.5 Tables- database-
MySQL - version -, database-
, tables-
. database- rename process
.
1. database - table -
. MySQL
Administrator tool - database -

.
2. database - , database-
database-
.
3. database - table - SHOW TABLES
RENAME TABLE command - , database -
.
4. database - users -, permissions
- database - .
5. test .
6. database -
database - .
Books database - library database - book,borrower &
loan 3 tables - code .
www.kaniyam.com

54

Temporarilydisablepermissions
CREATEDATABASElibrary;
RENAMETABLEbooks.bookTOlibrary.book;
RENAMETABLEbooks.borrowerTOlibrary.borrower;
RENAMETABLEbooks.loanTOlibrary.loan;
Migratepermissions
Reenablepermissions

4.6 database- table -


'Drop table' command database- table- .
DROPTABLEmarks;

www.kaniyam.com

55

'marks' table, 'exams' database- .

4.7 Tables -
command, default database- tables
- .
2 command- database-
, database - tables -
.
3 command, Like operator- condition -
tables- .
SHOWTABLES;
SHOWTABLESINdatabase_name;
SHOWTABLESLIKE'word%';

commands- outputs .

www.kaniyam.com

56

www.kaniyam.com

57

5 Columns -
Table - Columns - .
column - table -
. column -
, tables - back-up .
5.1 column- table-
table - Column-
. syntax .
ALTERTABLEtable_name
ADDCOLUMN[column_definition];
Create table statement.- Column definition -
, column definition . ,
Alter table table_name .
rank Column, 'marksheet'
table- .
ALTERTABLEmarksheet
ADDCOLUMNrankVARCHAR(10)NOTNULL;

www.kaniyam.com

58

5.2 Column-
table- column- , column-
process .
, Alter table add column Alter table
change column . syntax .
ALTERTABLEtable_name
CHANGECOLUMNcolumn_name[column_definition];
column definition type attributes - column
name - . column name - column
definition- statement-, column name
.
query-, 'marksheet' table - 'rank'
column- 'grade' .
, width- .

www.kaniyam.com

59

ALTERTABLEmarksheet
CHANGECOLUMNrankgradeCHAR(6)NOTNULL;

5.3 column- table-


. syntax .
ALTERTABLEtable_nameDROPCOLUMNcolumn_name;
column - , column row-
data-
.
query-, 'marksheet' table- 'grade' column
.
ALTERTABLEmarksheetDROPCOLUMNgrade;
www.kaniyam.com

60

www.kaniyam.com

61

6 Indexes -
Indexes table- column -
MySQL Server .
tables - data -
indexes .
6.1 Index- table-
Create index command - table-
columns- index- . syntax .
CREATEINDEXindex_name
ONtable_name(column_name,...);
syntax-, table- index - , index-
column-
.
query- index
.
CREATEINDEXaONmarksheet(student_id);

www.kaniyam.com

62

6.2 Index-
Index - .
index definition .
index - , index -
index - .
6.3 Index-
Index - syntax . table -
index - . syntax
.

DROPINDEXindex_nameONtable_name;

www.kaniyam.com

63

query- index .
DROPINDEXaONmarksheet;

6.4 Identifiers
MySQL Identifiers database column names
. case sensitive .
identifier- lower case letters - .
MySQL platform - , my.cnf file-
lower_case_table_names configuration variable 1 .
.
shell prompt- , 'my.cnf'- 'gedit'- open .

, 'my.cnf ' file- gedit- open . ,


lower_case_table_names=1 type .

www.kaniyam.com

64

case sensitive identifiers - lowercase- .


Identifier names -
.
http://dev.MySQL.com/doc/refman/5.0/en//identifier-case-sensitivity.html

www.kaniyam.com

65

7 Library ' Databases' -


database table-
.
database- . database-
library-

. database ,
.

Library-
.


, e-mail
.

7.1 Library Database-


Database data sets- . data sets tables-
. databases tables object-
MySQL- .
library database-
. database-
database .
root user login command-
MySQL- databases .
SHOWDATABASES;

www.kaniyam.com

66

command- install MySQL- run


databases- .

MySQL - administrative data MySQL server-

Test - ideas features-


sandbox- .

output- library databases


, database- .
CREATEDATABASElibrary;

command, execute MySQL client-


message- .
QueryOK,1rowaffected(0.01sec)

SHOWDATABASES;
run , library database-
database
.

www.kaniyam.com

67

library database,
tables container .
7.2 tables-
table-
.
tables . .

www.kaniyam.com

68

Library- - ,
.

-
.

-
.

table-
:- book title, book author,book condition, person name, person
email-id . table-
,
,
2 table- .
memory space- redundant
data- table- .
table-
, table- duplicate data- .
,
duplicate .
table-
,
table- query
.
Reference- book person tables ,
table- refer transaction
loan table- .
3 table- .

www.kaniyam.com

69

7.3 Book table-


command- book table- . query-
command line- enter , line- enter .
.
sql queries- MySQL-
(
string literals- .
library lib rary MySQL-
).
CREATETABLEbook(
book_idSMALLINTUNSIGNEDAUTO_INCREMENTNOTNULL,
titleVARCHAR(255)NOTNULL,
authorVARCHAR(255)NOTNULL,
condENUM('poor','good','middle')NOTNULL,
PRIMARYKEY(book_id)
);

code- .
Candidate Keys:
www.kaniyam.com

70

book table- title, author


condition 3 .
3 columns- . table-
candidate keys .

Primary Key:
table- column- title- candidate key
. primary key duplicate
column- title .
duplicate
candidate key- table- primary key- .
, synthetic primary key unique
column- primary key-
. candidate keys table- columns
. primary key- candidate
key- .
book table- 3 candidate keys .
book title, book author & book condition.
columns- duplicate . Duplicate
column- column-
duplicates . 3
column- duplicate
.
book_id synthetic primary key-

. column duplicate
. column table-
row- identify primary key .

www.kaniyam.com

71

Auto increment - primary key :


Auto-increment column -, table-
rows insert ,
column- . book table- book_id
primary key column- auto increment .
table- AUTO-INCREMENT column
primary key- .
7.4 Data Types:

Table- column- , column-


data- datatype column-
data .
book table- columns-

book_id column- .
column type- column-
.
library- database 50,000
. column-
UNSIGNED SMALLINT datatype- . 0-
65,535 datatype .
book title book author columns-
. CHAR
VARCHAR datatypes . Char
fixed-length varchar
(variable length) data type . 0-
255 characters .
www.kaniyam.com

72

condition column- .
column- good poor
.
row-
ENUM data
type .
column- ENUM data type
, column-
list- .
column- memory
space .

7.5 Column Names:


table- column-
.

lowercase letters-
table- primary key- column-
table- foreign key- . table-
column-
, primary key foreign key
.
Column- ,
column- column-
title . sql keywords- date
index column title- .
column- title-
,
Underscore(_) . .

book
table- columns-
,

www.kaniyam.com

73

Book_id
Title
Author
Cond

7.6 Person table-


person table- e-mail
. person table-
person name email address candidate keys .
table- table- person_id
primary key- . table-
row- refer primary key .
person_id column- data type- ,
table- data
. library-
.
column- UNSIGNED TINYINT data type .
0- 255 data type .
name e-mail columns-
, 0- 255
VARCHAR(255) datatype- .
person table- query
.
CREATETABLEperson(
person_idTINYINTUNSIGNEDNOTNULLAUTO_INCREMENT,
nameVARCHAR(255)
COMMENT"Theperson'sname",
emailVARCHAR(255)
COMMENT"Theperson'semailaddress",
PRIMARYKEY(person_id)
)COMMENT"Basicinformationaboutbookborrowers";
www.kaniyam.com

74

query query-
COMMENT keyword
. keyword, column table data-
optional keyword .

7.7 loan table-

table- candidate keys table- primary


keys- refer foreign key- . loan
table- 3 candidate keys .

book_id book table- primary key


person_id person table- primary key
date_lent column,
.

loan_id primary key- table-


. syntax .

www.kaniyam.com

75

CREATETABLEloan(
loan_idINTUNSIGNEDNOTNULLAUTO_INCREMENT,
person_idTINYINTUNSIGNEDNOTNULL,
book_idSMALLINTUNSIGNEDNOTNULL,
date_lentDATENOTNULL,
PRIMARYKEY(loan_id)
)COMMENT"Storeinfoonbookloans";

query- DATE datatype data type


. DATE data type-
column- 1000-01-01- 9999-12-31
data type .
book, person loan 3 tables- 'library'
database- .

www.kaniyam.com

76

tables- data- .

www.kaniyam.com

77

8 Library Database- data-

table- data- ,
insert statement
. syntax .
INSERT[INTO][db_name.]table_name
(list,of,columns,...)
VALUES(list,of,values,...)

Insert [into] - command- . Into optional


keyword .

table_name - data- table-


table- .

(list,of,columns.) - column- data


columns- parenthesis-
. columns row
default .

values - command MySQL


.

(list, of, values,.) - column-


, parenthesis
- .

insert statement table- row- insert .


row- .

www.kaniyam.com

78

8.1 book table- data-


book table- row
.

INSERTbook(title,author,cond)
VALUES('Silanerangalilsilamanithargal','Jayakanthan',
'good');

table- select statement


.
Insert keyword- book tablename
. INTO optional keyword
. book tablename-
, column- column
list . row- insert
list- columns- default insert .
www.kaniyam.com

79

list- book_id primary key column-


. row, insert
column- auto-increment
column- list- .
list- optional- . list
, table-
columns- .
column-
.
.
VALUES keyword- table-
parenthesis-
. parenthesis-
comma- .
quotes- .
.
, rows- table- ,
parenthesis- comma-
. parenthesis- semicolon(;) -
insert row-
.
book table- 3 rows
.
INSERTbook(author,title,cond)
VALUES
('StephenR.Covey','The7HabitsOfHighlyEffective
People','middle'),
('AmishTripathi','TheImmortalsofMeluha','poor'),
('MitchAlbom','TuesdayswithMorrie','good');

www.kaniyam.com

80

query
query- rows- insert .
8.2 Auto increment column- data-
row - insert , auto-increment
column- , column
www.kaniyam.com

81

. , column
. book
table- book_id column auto-increment
.
row- delete auto-increment column-
.
,
rows- , data-
.
row - insert , auto-increment column-
NULL
.
.
CREATETEMPORARYTABLEdemo(
idINTNOTNULLAUTO_INCREMENT,
PRIMARYKEY(id)
);
INSERTdemo()VALUES();
SELECTidFROMdemo;#idcontains1
INSERTdemo(id)VALUES(NULL);
SELECTidFROMdemo;#idcontains1and2

www.kaniyam.com

82

INSERTdemo(id)VALUES(4);
SELECTidFROMdemo;#idcontains1,2and4
INSERTdemo(id)VALUES(NULL);
SELECTidFROMdemo;#idcontains1,2,4
and5
www.kaniyam.com

83

8.3 Person table- data-


person table-
insert .

www.kaniyam.com

84

INSERTperson(name,email)
VALUES('Nithya','nithyadurai87@gmail.com'),
('Shrinivasan','tshrinivasan@gmail.com'),
('Kanmani','Kanmanishrini@gmail.com');

table- select statement


.

8.4 file- queries data- table-


SQL commands MySQL command-line -
run . commands- text
www.kaniyam.com

85

file- , MySQL ( client)


run .
'Batch mode' . syntax .
shell>MySQLuusernamepdb_name<file_name.sql
syntax .
1. shell> prompt - MySQL server- username-
connect .
2. authenticate password prompt- .
3. db_name default database
4. commands file_name.sql file- server-
.
5. , commands execute results
.
6. exit .
, MySQL command-line ,
query- .
mysql>\.file_name.sql
person table-, 'batch mode'
data . queries- file-
enter , 'queries.sql' save .
.

www.kaniyam.com

86

MySQL command line-, enter .


mysql> \. queries.sql

file- data-, table- insert .

www.kaniyam.com

87

8.5 table- data- table- insert


Insert command- select command-
table- copy rows- table- insert
.
INSERT----SELECT command- syntax . Insert
command- (VALUES clause ) Select command-
. .

INSERTtable_one(list,of,columns)SELECT...;
, 'person' table- data-, 'info'
table- query- .
INSERTinfo(id,name,email)SELECT*fromperson;

www.kaniyam.com

88

Insert command- column-, select


statement- column, return
.
8.6 file- data- table-
Data- applications- MySQL- import ,
data- text format (Eg: tab-separated
values) MySQL- import .
data- set of SQL queries-
import . ,
,
.
LOAD DATA INFILE command, text files-
www.kaniyam.com

89

data- MySQL-
. syntax .
LOADDATAINFILE'some_file.txt'
INTOTABLE'some_table'(list,of,columns,...);
text file- data- field- tab-,
row- line- .
LOAD DATA INFILE command, file-
import
. file- row- command- read
table- column mapping-
row .
/home/nithya/data.txt
file person table-
.

upload command .
LOADDATAINFILE'/home/nithya/data.txt'
INTOTABLEperson(name,email);
www.kaniyam.com

90

command, run , book table-, file-


data .

LOAD DATA INFILE command- .

MySQL server machine- datafile .

Data load file-


path- .
, MySQL server path- ,
data directory-

Windows systems- blackslashes- forward


slash- path- . unix-style path
('/home/nithya/data.txt') ,
windows- 'C:/Desktop/data.txt' .
blackslashes- character escape sequences-
interpret .

, load data infile -


.

www.kaniyam.com

91

command- output warning error-


(eg:
QueryOK,3rowsaffected,1warning(0.01sec))
SHOW WARNINGS SHOW ERRORS command-

8.7 loan table- data- insert


data- insert book person
table- . "" "
"
primary key- .
primary key- loan table-
.
primary key- , query-
.
SELECTperson_idFROMpersonWHEREname='Nithya';

output primary key '1' .


www.kaniyam.com

92

" " primary key-


, query- .
SELECTbook_idFROMbookWHEREtitle='silanerangalilsila
manithargal';

output " " primary


key '1' .

" "
loan table- .

INSERTloan(book_id,person_id,date_lent)
VALUES(1,1,'20121119');

www.kaniyam.com

93

table- user
variable- assign , user variable- query-
.
user variable- format, @name . name
A-Z , 0-9
$,- user variable-
.
variable- := operator-
assign . :
SELECT@place1:='Kanchipuram';
'Kanchipuram' '@place1' user
variable . query- , run
variable .
SELECT@place1;

www.kaniyam.com

94

loan table- user variable- ,


. user variable data- table-
, .
SELECT@person_id:=person_idFROMperson
WHEREname='Shrinivasan';
SELECT@book_id:=book_idFROMbook
WHEREtitle='TuesdayswithMorrie';
SELECT@date:='20120804';
INSERTloan(book_id,person_id,date_lent)
VALUES(@book_id,@person_id,@date);

www.kaniyam.com

95

select statement- user variable


. select statement-
table- insert .

www.kaniyam.com

96

SELECT@book_id:=book_id,
@person_id:=person_id,
@date:='20121212'
FROMbook,person
WHEREbook.title='silanerangalilsilamanithargal'
ANDperson.name='Kanmani';
INSERTloan(book_id,person_id,date_lent)
VALUES(@book_id,@person_id,@date);

www.kaniyam.com

97

queries- user variables


query- optimize . .
INSERTloan(book_id,person_id,date_lent)
SELECTbook_id,person_id,'20121231'
FROMbook,person
WHEREbook.title='silanerangalilsilamanithargal'
ANDperson.name='Shrinivasan';


. query-
queries-
.

www.kaniyam.com

98

8.8 Function date- insert


Now() function, query- , MySQL server
machine- , machine- date time-
insert . syntax .
INSERTsome_table(some_column)VALUES(NOW());
SQL- Now ()- function
date time- column- insert
.
function return text-
punctuation- .
,
SELECTNOW();
run . format- date time-
return .

,
www.kaniyam.com

99

SELECTNOW()+0;
run , format- date- return .

'loan' table-, insert


, now() function- ,
INSERTloan(person_id,book_id,date_lent)VALUES
('3','2',NOW());

www.kaniyam.com

100

www.kaniyam.com

101

9 Library Database-
data-
table- queries-
.
query table- data- return .
SELECT*FROMbook;

9.1 Limit Clause-


LIMIT Clause- rows-
query- . .
SELECTauthorFROMbookLIMIT2;
# 2 rows- return .
SELECTauthorFROMbookLIMIT2,2;
# 2 rows- , 2 rows- return .
www.kaniyam.com

102

SELECTauthorFROMbookLIMIT3,2;
# 3 rows- , 2 rows- return .

LIMIT Clause rows-


.
9.2 Order by result-
MySQL- rows
.
order by clause-
. order by clause- column-
table- .
.
www.kaniyam.com

103

SELECT*FROMbookORDERBYtitle;
# 'book' table- records-, title-
.

code- .
query, server- .
SELECT*FROMbookORDERBYtitle;
query, return row- title- list-
. .
Sila nerangalil sila manithargal (Row 1)
The 7 Habits of Highly Effective People (Row 2)
The Immortals of Meluha (Row 3)
Tuesdays with Morrie (Row 4)
Kallo kaaviyamo (Row 5)
Thanneer thesam (Row 6)
Yen Yetherku Yeppadi (Row 7)

www.kaniyam.com

104

title row- server-


.
list- alphabetical
. case-sensitive .
Kallo kaaviyamo (Row 5)
Sila nerangalil sila manithargal (Row 1)
Thanneer thesam (Row 6)
The 7 Habits of Highly Effective People (Row 2)
The Immortals of Meluha (Row 3)
Tuesdays with Morrie (Row 4)
Yen Yetherku Yeppadi (Row 7)
list- , rows-
.
9.3 DISTINCT data-

Distinct keyword data-


.
'book' table- 'cond' column-, 'distinct'
keyword data-
. 'distinct'
data- .
.
SELECTcondFROMbook;
SELECTDISTINCTcondFROMbook;

www.kaniyam.com

105

query, 'cond' column- data- rows -


, data- return .
query- select- distinct clause -
, data- return
duplicate data- .
9.4 data- ' like'
Like operator- pattern-
. book- table- , T-
, query-
.
SELECTtitleFROMbookWHEREtitleLIKE'T%';

www.kaniyam.com

106

e
, query- .
SELECTtitleFROMbookWHEREtitleLIKE'%e';

Like operator
wildcard characters .

%(Percent) - 0
characters- .

_(Underscore) - character-
character- .

www.kaniyam.com

107

book- table- S
, 8 author-
query- .
SELECTauthorFROMbook
WHEREauthorLIKE'S________%';

'Sujatha' author- .
7 .

9.5 Aggregate functions data-


MySQL- column-
group functions .
min() function column- ,
.
max() function column-
.
avg() function column-

www.kaniyam.com

108

average
.
.

SELECTMIN(marks),AVG(marks),MAX(marks)FROMperson;

9.6 Date functions


Date time- MySQL-
functions . MySQL-
.

YYYYMMDDHH:MM:SS(Eg:'2005093018:43:01')

YYYYMMDDHHMMSS(Eg:20050930184301)

www.kaniyam.com

109

CURDATE() function ,
CURTIME() function ,
now() function .
.

DATE_ADD() DATE_SUB() functions

date/time-
.
, greater than(>),less than(<) equal
to(=) .
SELECT*FROMloan
WHEREdate_lent<=
DATE_SUB(CURDATE(),INTERVAL1WEEK);
www.kaniyam.com

110

SELECT*FROMloan
WHEREdate_lent>=
DATE_SUB(CURDATE(),INTERVAL1WEEK);

query- loan
table-,
data- .
query- loan table-,
data
data- .
www.kaniyam.com

111

Date time functions- ,


program-
time zones, daylight savings time, wandering system clocks

.

.

Network Time Protocol(NTP) - ,


.

,
.

,
Greenwich Mean Time(GMT) Coordinated Universal
Time(UTC)- .
logic- program- .
.

9.7 Decimal columns


MySQL- decimal
columns- . decimal columns
floating point numbers- strings- .
,
, data
.
decimal column- data
MySQL- version- . MySQL- manual-
. versions-
30

www.kaniyam.com

112

9.8 NULL-
NULL . empty zero-
. queries- .
SELECTNULL=FALSE;
SELECTNULL='';
SELECTNULL=0;
SELECTNULL=NULL;

www.kaniyam.com

113

queries- null . null


data .
null- boolean false- , empty string-
, 0 integer
null- , null .
.
null column-
.

column- null comparison


operators- .
query rows- return .
SELECT*FROMbookWHEREtitle!=NULL;

null , Special Null


Safe Operators ISNULL <=> -
.

9.9 Query result- file-


INTO OUTFILE INTO DUMPFILE clause-
.
1. INTO OUTFILE
www.kaniyam.com

114

INTO OUTFILE clause- select statement- , query


file- .
clause- simple select statement
, select query-
, INTO OUTFILE- file- tab
separated format- . file- , field-
tab-, row-
.
SELECT*FROMbook
INTOOUTFILE'/tmp/book'
FIELDSTERMINATEDBY','
ENCLOSEDBY'"'
LINESTERMINATEDBY'\n';

query, CSV file- .


format- query-
. Character sequences \n \t
line- tab- MySQL server-
interpret .

www.kaniyam.com

115

2. INTO DUMPFILE
INTO DUMPFILE clause- select
statement-
file- .
INTO DUMPFILE clause row- return select
statement- . select statement-
columns
file- .
.
SELECT*FROMbook
WHEREbook_id=5
INTODUMPFILE"/tmp/book1";

www.kaniyam.com

116


file- .

www.kaniyam.com

117

10 Library database-
Tables-
queries- table-
. ,
sql- Joins, Subqueries Union
queries- ,
tables-
.
10.1
Relational databases- , data-
tables-
. table- row-
column- table- primary key
. table- primary key
column, table- primary key- ,
table- foreign key .
book table- book_id primary key ,
column table- row-
. , person table- person_id
column table- row-
.
loan table- "
" book
person table- .
loan table- book_id
person_id columns, table- foreign key .

www.kaniyam.com

118

,
loan table- , book_id
column- book table-
.
, loan
table- person_id person table-
. loan table-
. transaction
date_lent column .
loan,person book tables-
.
10.2 Where clause tables-
tables- data-
, tables- primary key foreign key
.
, tables- data-
tables- select statement- from clause-
. where clause- tables-
primary key-foreign key .
syntax .

SELECTcolumns
FROMtable1,table2
WHEREtable1.foreign_key=table2.primary_key;
where clause- . ,
, table- row- ,

www.kaniyam.com

119

table- row-
result .
query-, loan, person book
tables- ,
.

SELECTloan.date_lent,person.name,book.title
FROMloan,book,person
WHEREloan.book_id=book.book_id
ANDloan.person_id=person.person_id;
query- select statement- column-
prefix, column table-
qualifier . columns
tables- , column- table-
MySQL- error- .
column- table
name- qualifier- .
query- output .

www.kaniyam.com

120

, filters- AND keyword


conditions- result-
.

SELECTloan.date_lent,person.name,book.title
FROMloan,book,person
WHEREloan.book_id=book.book_id
ANDloan.person_id=person.person_id
ANDperson.name='Nithya';

10.3 Join keyword tables-


Join keyword tables select statement- from
clause- tables Join
keyword- . ON
clause- tables- primary key-foreign key
.

www.kaniyam.com

121

syntax .
SELECTcolumns
FROMtable1
JOINtable2
ONtable1.foreign_key=table2.primary_key;
Join tables- queries,
. Joining conditions ON clause-
, where clause- conditions-
.
Join keyword tables- Inner join Outer Join
.
10.4 Inner join tables-
Where clause- ,
Join keyword .
.
SELECTloan.date_lent,person.name,book.title
FROMloan
JOINbook
ONloan.book_id=book.book_id
JOINperson
ONloan.person_id=person.person_id;

www.kaniyam.com

122

query- tables Inner join .


10.5 Table aliases-
examples- columns
table name- . table
name ,
column name-
. ,
query- . alias name
.
alias name , clause- table-
AS keyword-
.
.
SELECTa.date_lent,b.title,c.name
FROMloanASa
JOINbookASb
ONa.book_id=b.book_id

www.kaniyam.com

123

JOINpersonASc
ONa.person_id=c.person_id;

a,b,c 3 alias name loan,book person 3


tables- .
query- table name- alias-
, query alias- .
alias- table-
.
10.6 Outer Join tables-
Outer Join- left outer join right outer join .
Left outer join- Join keyword- table-
row- return . table,
Joining condition- , table-
.
table- NULL .
syntax .

www.kaniyam.com

124

SELECTcolumns
FROMtable1
LEFTOUTERJOINtable2
ONtable1.foreign_key=table2.primary_key;
loan person table- ,
, Outer Join query-
.
SELECTp.name,MAX(l.date_lent)
FROMpersonp
LEFTOUTERJOINloanl
ONp.person_id=l.person_id
GROUPBYp.name;
Query- output .

person table-
.
table- .
table, NULL-
.
www.kaniyam.com

125

Right outer join- table-


, table-
. table-
NULL .
10.7 Column alias-
Table- alias name- , Column- alias name-
. , query-
select statement- column- aggregate
functions , return , column
name- . return
column name column- alias
name- . .

SELECTp.name,MAX(l.date_lent)asmaximum_date
FROMpersonp
LEFTOUTERJOINloanl
ONp.person_id=l.person_id
GROUPBYp.name;

www.kaniyam.com

126

query table-
column- data- , result set-
, column table-
.
columns- alias name-
.
10.8 Subquery tables-
queries subquery
. select statement- query-
conditions- paranthesis-
query subquery . subquery- execute
. subquery-
main query- execute . syntax
.
SELECTcolumns
FROMtable1
WHEREcol1IN(SELECTcol2FROMtable2WHERE...);
www.kaniyam.com

127

syntax- subquery where clause- In


operator- . subquery column-
return . return
main query- .
Subqueries- non-correlated subquery correlated subquery
.
10.9 Non- correlated subquery
Non-Correlated subqueries- outer query-
table- subquery- table-
condition- .
'book' table- cond column
good bad
. cond column- good

non-correlated subqueries
. .
SELECTDISTINCTb.name
FROMloana
JOINpersonb
ONa.person_id=b.person_id
WHEREa.book_idIN(SELECTbook_idFROMbookWHEREcond
='good');
query- paranthesis- subquery
.
main query ,

. output .

www.kaniyam.com

128

subqueries- ,
queries- execute .
.
SELECTbook_idFROMbookWHEREcond='good';
SELECTDISTINCTb.nameFROMloanaJOINpersonb
ONa.person_id=b.person_idWHEREa.book_idIN(1,4,5,8,9);
query,
.
result- condition- query,

.

www.kaniyam.com

129

queries- ,
subquery- query- . subquery-
.

10.10 Select statement- Subquery-


Subquery- select statement- columns-
. subquery- column-
. MySQL, error- .
query,
table- data- summary
.
SELECT(SELECTCOUNT(*)FROMperson)ASNo_of_persons,
(SELECTCOUNT(*)FROMbook)ASNo_of_books;

www.kaniyam.com

130

select statement- columns-


subqueries . return
row- .
10.11 Correlated subquery
Correlated subqueries- outer query- table-
subquery- table- condition-
.
book table- main query- return
,
query-
.
SELECTb.title,
(SELECTmax(date_lent)FROMloanaWHEREa.book_id=
b.book_id)ASlast_lend_date
FROMbookb;

www.kaniyam.com

131

sub query- loan table-, main query- book


table-, book_id column-
. correlated subquery .
subquery- row- execute
mainquery- . correlated subquery
query- run .
10.12 Union queries-
UNION Operator queries
resultset- .
syntax .
SELECTcolumnsFROMtable1
UNION
SELECTcolumnsFROMtable2;
queries execute
www.kaniyam.com

132

UNION Operator ,
result set .

SELECT*FROMbook
UNION
SELECT*FROMloan;

Union Operator query-


columns .
Union Operator,
.
, UNION UNION ALL keyword-
.
UNION UNION ALL-
.
SELECTcondFROMbookwherecond='good'
www.kaniyam.com

133

UNION
SELECTnameFROMperson;

SELECTcondFROMbookwherecond='good'
UNIONALL
SELECTnameFROMperson;

good
.

www.kaniyam.com

134

11 Library database-
data-
,
.
.
'update' command, table- data-
. syntax .
UPDATEtable_nameSETcolumn_name=valueWHEREcondition;
syntax .

UPDATE - query, run


.

SET - column-
. column-
, .
SET name0='value', name1='some_other_value',
...

WHERE - clause row-


condition- .

Column-
. query, book table-
'cond' column- good .
UPDATEbookSETcond='good';

www.kaniyam.com

135

row- query-
.
UPDATEbook
SETcond='poor'
WHEREauthor='Jayakanthan';

www.kaniyam.com

136

row- author- Jayakanthan ,


row- 'cond' column, 'poor' .
11.1 Function column-
query-, loan table-
DATE_ADD function . DATE_ADD
function-, ,
.
UPDATEloan
SETdate_lent=DATE_ADD(date_lent,INTERVAL1YEAR)
WHEREdate_lent='20121231';

www.kaniyam.com

137

update queries, table-


.

www.kaniyam.com

138

12 Library database-
data-
table- row- 'delete' command
. syntax .
DELETEFROMtable_nameWHEREsome_conditions;

DELETE - query- . query


.

FROM - table- .

WHERE - conditions , rows


.

query- 'book' table- , 'cond'


column- poor row .
DELETEFROMbookWHEREcond='poor';

12.1 tables- rows-


query- book loan tables- rows-
condition- .

www.kaniyam.com

139

DELETEbook,loan
FROMbook,loan
WHEREbook.book_id=loan.book_id
ANDbook.cond='poor';

syntax .

Delete - query- . query


.

list,of,tables - tables-
rows .

FROM - condition- .

list,of,tables - tables where


clause- condition- .

WHERE - conditions , rows


.

12.2
MySQL- 'undo'
. ,

www.kaniyam.com

140

DROPDATABASElibrary;
query- run , 'library' database-
tables- .
queries , run , undo
. logs, backups data recovery tool
.
'library' database- data-
.

Users-, permissions- .
database-
, database- root account-
. , select queries run
permissions user- create , user
login . , adhoc
queries- run
.

Server Administrator , MySQL-


backup
.

adhoc backups- .
adhoc backups server admin backup
,
backup .

option, delete update queries- LIMIT


WHERE clauses .
queries (conditions
) table-

www.kaniyam.com

141

. options-
.
SETSQL_SAFE_UPDATES=1;

MyISAM non-transactional storage engine-


, queries- table- run
table- run
.
command, book table- copy test
table- .
CREATETEMPORARYTABLEtestLIKEbook;
INSERTtestSELECT*FROMbook;
commands- test table- run
book table- run .

databases- .

InnoDB BerkeleyDB storage engine-


queries- run .
transaction- queries
COMMIT .

www.kaniyam.com

142

ROLLBACK
.
transaction-,
rollback- commit- .

BEGIN;
UPDATEbookSETauthor="Sujatha";
SELECT*FROMbook;
ROLLBACK;
BEGIN;
UPDATEbookSETAUTHOR="Sujatha"
WHEREauthor="Vairamuthu";
SELECT*FROMbook;
COMMIT;

www.kaniyam.com

143

13 Users-
MySQL users database .

.
MySQLs privilege system
database -
. username database
remote address .
, password-
database - .
13.1 Server- user-
user- , admin rights
. , MySQL- install 'root'
user, 'admin rights' user- . syntax
.
CREATEUSERuser@hostIDENTIFIEDBY'password';
, Nithya' user, 192.168.1.10
remote IP address- . remote IP
address- abcd password- login .
ip address- password
login .
CREATEUSER'Nithya'@'192.168.1.10'
IDENTIFIEDBY'abcd';

www.kaniyam.com

144

, ip address ,
local host name domain name
.
MySQL
database- localhost . .
CREATEUSER'Nithya'@'localhost'
IDENTIFIEDBY'super';

'Nithya'
user , password-
.
create user command, MySQL version 5.0.2
version- . version-
command . version- database
, MySQL tables- user,host database-
. version- ,
user table- insert command-
. .

www.kaniyam.com

145

INSERTINTOuser(Host,User,Password)
VALUES('123.456.78.90','Nithya',
PASSWORD('abcd'));
FLUSHPRIVILEGES;

query- abcd password ,


PASSWORD() function .
password, encrypt
user table- .
FLUSH PREVILEGES command .
user table- data , privileges-
reload . create user command-
.
13.2 user- server-
DROP USER command-, user- user
table- .
DROPUSERNithya@localhost;

www.kaniyam.com

146

user ,
active user session-
. session-
.
drop user command, MySQL version => 5.0.2-
. version- delete
command . .
DELETEFROMuser
WHEREUser='Nithya'
ANDHost='192.168.1.10';
FLUSHPRIVILEGES;

13.3 user-
. username
,
username surname- .
surname ,
username- .
" " ,
" " , RENAME USER command

www.kaniyam.com

147

- , .
RENAMEUSERold_user@hostTOnew_user@host;
rename user command, MySQL version >= 5.0.2-
. version-
update command . .

UPDATEuser
SETUser='Nithya_Shrinivasan'
WHEREUser='Nithya_Duraisamy'
ANDHost='localhost';
UPDATEdb
SETUser='Nithya_Shrinivasan'
WHEREUser='Nithya_Duraisamy'
ANDHost='localhost';
FLUSHPRIVILEGES;

www.kaniyam.com

148

update command, user table-,


rows- database table- .
13.4 Wildcards- IP address- users-

Percent (%) Underscore(_) wildcard characters-


pattern- ip address-
, IP
.
CREATEUSER'Karthik'@'192.168.0.%'
IDENTIFIEDBY'abcd';
www.kaniyam.com

149

192.168.0.x IP range- IP
.
,
login username password-
query- .
CREATEUSER'Karthik'@'%'IDENTIFIEDBY'phrasebook';

13.5 database/ table-

SELECTDbFROMdb
WHEREUser='user'ANDHost='host';
SELECTTable_nameFROMtables_priv
WHEREUser='user'
ANDHost='host'ANDDb='db';
database- db
table- user host- query- .

www.kaniyam.com

150

SELECTDb,Table_nameFROMtables_priv
WHEREUser='Nithya'ANDHost='localhost'
user, tables-
tables_priv table- user, host db
condition- query- .
13.6 Password -
MySQL - user- login ,
password- query- .
SETPASSWORD=PASSWORD('murali');

'murali' password .
admin- login ,
password- query- .
SETPASSWORDFORkumar@localhost=
PASSWORD('xxxx');

www.kaniyam.com

151

'xxxx' 'kumar'- password .


update query - .
UPDATEuser
SETPassword=PASSWORD('xxxx')
WHEREUser='kumar'ANDHost='localhost';
set password command- FLUSH
PRIVILEGES - .
13.7 Users- tables- privileges-

Grant command- database tables-


users- .
syntax .
GRANTprivilegesONdb.table
TOuser@host
IDENTIFIEDBY'password';
, MySQL version 4.1- GRANT
command- user- .
user- comma
.
karthik- user- library database-
'book' table- select insert
. data-
.

www.kaniyam.com

152

GRANTSELECT,INSERTONlibrary.book
TO'karthik'@'localhost'IDENTIFIEDBY'bca';

user- , ALL
PRIVILEGES ALL keyword- .
'kumar' user- library database- 'book'
table- .
GRANTALLPRIVILEGESONlibrary.book
TO'karthik'@'localhost';

user- ,
IDENTIFIED BY clause - .

www.kaniyam.com

153

13.8 User privileges


User privileges -
privileges .
,
with grant option -
. privileges-
. syntax .
GRANTprivilegesONdb.table
TOuser@host
IDENTIFIEDBY'password'
WITHGRANTOPTION;
, privileges-
, permissions users
privileges - .
13.9 User- privileges-
Show grants command- user-
privileges- .
SHOWGRANTSFORkarthik;

www.kaniyam.com

154

command- ,
Grant statements- .
SHOWGRANTSFOR'karthik'@'localhost';

statement- password,
password- encrypt .
www.kaniyam.com

155

FOR clause grant statement user-


current_user() - , privileges- .
13.10 user-
Revoke- privileges- .
privileges
comma- , ALL keyword-
privileges- .
query, 'karthik' user- select
privilege- library database- book table-
.
REVOKEselectONlibrary.book
FROMkarthik@localhost;

query, user- grant


option- privileges- .
REVOKEALLPRIVILEGES,GRANTOPTION
ONsampdb.mytable
FROM'shrini'@'localhost';

www.kaniyam.com

156

13.11 Network access-


TCP/IP remote access- my.cnf-
skip-networking- skip-networking switch
mysqld- start . MySQL, localhost-
socket .

#mysqld_safeskipnetworking&
Network access- disable , user- remote
hosts MySQL- .
MySQL- remote access- , MySQL-
firewall, appropriate port-
. , 3306 port .

13.12 User authentication-


password- .
password- reset , MySQL- password
restart
Admin rights .
MySQL server- , master my.cnf file-
skip-grant-tables restart . - skip-grant-tables switch- mysqld- restart .
#mysqld_safeskipgranttables&
restart , password
MySQL- .

www.kaniyam.com

157

MySQLuroot
password MySQL- ,
password- .
updateusersetpassword=PASSWORD("NEWROOTPASSWORD")where
User='root';
user authentication- enable FLUSH PRIVILEGES
command- MySQL server- -skip-grant-tables
restart .
13.13 SSL -
MySQL database server- client- encrypt
network SSL- .
, server- compile enable
. enable
command- .
SHOWVARIABLESLIKE'have_openssl';
command, Yes No variable-
.
compile time- enable ,
server- --with-vio --with-openssl
configure switches- recompile .
encrypt SSL ,
certificate files- .
certificate authority certificate, server certificate client
certificate .
www.kaniyam.com

158

my.cnf file- [mysqld] , .


certificate files
.
sslca=/path/to/CAcert
sslcert=/path/to/servercert
sslkey=/path/to/clientcert
file- [client] server settings- client
settings- . server- ,
certificate files- client- .
, certificate- MySQL- command-line
argument- .

MySQLsslca=/path/to/CAcert\
sslcert=/path/to/servercert\
sslkey=/path/to/clientcert

www.kaniyam.com

159

14 MySQL- Application Programming


Interface - API
MySQL server-
API . programming
API-
. API , Open
database connectivity ODBC MySQL server-
.
14.1 C API
C API-, API-
. API-
function call- , C library function-
.
C API- program-
libmysqlclient.so- . library- source-
MySQL- compile install .
components- binary distributions-, MySQLdevel*
platform- install .
libraries header files package- .
MySQL API- C program, MySQL.h file-
. file system-
include directory- . .
#include<mysql/mysql.h>
libmysqlclient.so- compiler- .
gcc mytest.c program,

www.kaniyam.com

160

compile libmysqlclient-
.

shell>gccomytestmytest.clmysqlclient
compile , error messages ,
mysql_config utility- compiler
options . cflags, --include
libs switches- mysql_config- run ,
. .
shell>mysql_configcflagsincludelibs
I/usr/include/mysqlmcpu=i486fnostrengthreduce
I/usr/include/mysql
L/usr/lib/MySQLlMySQLclientlcryptlnsllmlzlc
lnss_fileslnss_dnslresolv
lclnss_fileslnss_dnslresolv
14.2 MySQL-
MySQL database- mysql_init()
mysql_real_connect() function calls .
function, MySQL type- object- initialize .
function, object- argument-
. , API calls- , object
database connection-
Resource argument- .
Port argument database- TCP/IP Port-
. localhost 0- .

www.kaniyam.com

161

MYSQLmysql;
mysql_init(&mysql);
mysql_real_connect(&mysql,"host","user",
"password","dbname",
port,unix_socket,client_flag);
, socket- named pipe-
unix socket argument- NULL- .
mysql client library- features- enable ,
client_flag argument- NULL- .
mysql_real_connect() -
return mysql object . object-
argument- object- .
variable- assign . ,
, function, NULL
return .

14.3 Query- execute


mysql_query() function query- execute .
function- argument- query NULL terminated
string- . semicolon
. query, mysql object-
database connection- execute .
query-, binary data- ,
mysql_real_query() function- query- length-
.
binary data- \0 character- ,
mysql_query() function, string-
\0- .

www.kaniyam.com

162

binary data- query- mysql_real_query() function-


.
mysql_query(&mysql,"query");
mysql_real_query(&mysql,"query",length);
Query- execute , query
function NULL- .
, function ,
.
ErrorCodesfrommysql_query()
CR_COMMANDS_OUT_OF_SYNCCommandswereexecutedinanimproper
order.
CR_SERVER_GONE_ERRORTheMySQLserverhasgoneaway.
CR_SERVER_LOSTTheconnectiontotheserverwaslostduring
thequery.
CR_UNKNOWN_ERRORAnunknownerroroccurred.

14.4 Result set-


query return ,
query- result- MYSQL_RES object- assign .
mysql_use_result() function execute query-
result- object- assign . result-
object- assign , reference-
query- execute .
query- execute , function, NULL
. ,
error code- .

www.kaniyam.com

163

MYSQL_RESresult;
MYSQL_ROWrow;
result=mysql_use_result(&mysql);
row=mysql_fetch_row(result);
mysql_fetch_row() function, execute query-
row- mysql_row structure-
. row[0]- , row[n-1]
row- . n data set- column-
.
mysql_num_fields() column- ,
mysql_num_rows() rows- .
14.5 Error Messages-
mysql_errno() mysql_error() functions ,

message- .
function arguments MySQL object .
function- return error
, execute query-
error . execute
query mysql_errno()
function, 0- mysql_error() function, NULL
return .
mysql_errno(&mysql);
mysql_error(&mysql);
functions- database-
query- execute
www.kaniyam.com

164

14.6
MySQL ,
,
mysql_close() function . mysql_init() allocate
resource- de-allocate .
mysql_close(&mysql);

#include <stdio.h>
#include <mysql/mysql.h>
main() {
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int numrows, numcols, c;
mysql_init(&mysql);
/* Establish a database connection */
if (!mysql_real_connect(&mysql, "localhost",

www.kaniyam.com

165

"username", "password",
"dbname", 0, NULL, 0))
{
fprintf(stderr,
"Failed to connect to database: Error %d:
%s\n", mysql_errno(&mysql),
mysql_error(&mysql));
}
/* Execute a query */
char query[] = "SELECT book_id, cond, title
FROM book";
if (mysql_query(&mysql, query))
{
fprintf(stderr,
"Error executing query: Error %d: %s\n",
mysql_errno(&mysql), mysql_error(&mysql));
}
/* Assign the result handle */
result = mysql_use_result(&mysql);
if (!result)
{
fprintf(stderr,
"Error executing query: Error %d: %s\n",

www.kaniyam.com

166

mysql_errno(&mysql), mysql_error(&mysql));
}
/* Find the number of columns in the result */
numcols = mysql_num_fields(result);
/* Loop through the result set to display it */
while (row = mysql_fetch_row(result)) {
for(c=0; c<numcols; c++) {
printf("%s\t", row[c]);
}
printf("\n");
}
}

14.7 Perl API


DBI (Database Interface) DBD (Database Driver) perl
MySQL- . Perl 5.6.0
versions .
DBI install Cpan download
install . .
shell>cpan
cpan>installDBI
www.kaniyam.com

167

windows platform- Activeperl distribution- , ppm.bat


script- perl modules- install .
C:\perl\bin>ppm.bat
ppm>installDBI
MySQL database driver- , DBD::MySQL module-
install .
cpan>installDBD::mysql
MySQL DBD- perl script-,
.
useMysql;
14.8 MySQL-
MySQL object- connect method database-
. dbh database handle- .
localhost- undef
argument- . DBI method, C API-
mysql_init() mysql_real_connect() functions-
.
$dbh=Mysql>connect(host,dbname,
user,password);

14.9 Query- execute

www.kaniyam.com

168

query- execute , dbh- sql statement- argument-


, query() method- . sth statement
handle- .
$sth=$dbh>query(query);

14.10 Result set-


@row=$sth>fetchrow;
sth- fetchrow() method- array data-
. fetchrow method ,
dataset- row- .
row- .
records , NULL- .
sth- numrows method, rows-
, numfields method, columns-
.
14.11 Error Messages-
errno errstr methods error error
. methods , dbh-
, execute query-
.
$errno=$dbh>errno;
$errstr=$dbh>errstr;
connection-
, methods- MySQL object- .

www.kaniyam.com

169

$errno=Mysql>errno;
$errstr=MySQL>errstr;

14.12
DBI method- .
program- exit , resources
. Exit , resource-
undef command- handle- .

#!/usr/bin/perl
useMysql;
/*Establishadatabaseconnection*/
$dbh=Mysql>connect(undef,"dbname","username","password")
ordie("Failedtoconnecttodatabase:Error"
.Mysql>errstr);
/*Executeaquery*/
$sql_statement="SELECTbook_id,cond,titleFROMbook";
$sth=$dbh>query($sql_statement)
ordie("Errorexecutingquery:Error".
$dbh>errno);
/*Loopthroughtheresultsettodisplayit*/

www.kaniyam.com

170

while(@row=$sth>fetchrow){
for($i=0;$i<$sth>numfields;$i++){
print$row[$i]."\t";
}
print"\n";
}
14.13 PHP API
PHP Applications- MySQL database-
.
PHP enable web server- MySQL- support-
<?php phpinfo();?> script-
.
script- web browser- MySQL support MySQLi support
. MySQLi MySQL Improved PHP
API- version . MySQL 4.1.3
version- . procedural
object-oriented . MySQLi-
. MySQL API , MySQLi- procedural
. Compile time- MySQLi support-
withmysql=/path/to/mysql_config switch-
enable .
14.14 MySQL-
$conn=mysqli_connect("host","user",
"password","dbname");
$conn=newmysqli("host",
"user","password","dbname");
www.kaniyam.com

171

syntax- mysqli_connect() functions


arguments- dbh database connection handle-
.
syntax- , MySQLi object-
constructor method- .
procedural object-oriented
. database operations
mysqli_connect()- arguments- ,
functions- MySQLi object- instance
methods .
14.15 Query- execute
Procedural mysqli_query() function , query-
argument- result handle- .
result handle , returned data-
functions- argument- .

$result=mysqli_query(query,$conn);
$result=$conn>query(query);
Object-oriented query() function, query-
argument- result handle- . result
object- , object-
methods- queries- process .
14.16 Result set-
procedural mysqli_fetch_array() function
, result- data record- .
www.kaniyam.com

172

object-oriented result handle object-


fetch_array() function- .
data NULL-
return .
$row=mysqli_fetch_array($result);
$result>fetch_array();
Array- return numeric associative
indexes- .
Numeric index- 0- select
columns- . Associative
indexes- , column- query-
aliases- .
query- return rows- procedural
mysqli_num_rows() function-, object-oriented
result object- num_rows() attribute-
. mysqli_num_fields num_fields
query- return column- .
14.17 Error Messages-
Procedural , mysqli_error() function, Connection handle-
argument- , connection- execute
query- error .
mysqli_error($conn);
$conn>error();
Object-oriented connection object- error() method
. error

www.kaniyam.com

173

mysqli_errno() errno() .
14.18
PHP script MySQL resources
.
mysqli_close($conn);
$conn>close();
, resources-
procedural mysqli_close() function-
object-oriented conn object- close()
method- . Database , result resource-
procedural mysqli_free_result()
function object-oriented result object-
free_result() method .

<?php
/*Establishadatabaseconnection*/
$conn=newmysqli("localhost","user","password","dbname");
if(!$conn){
echo"Failedtoconnecttodatabase:Error".
$conn>error()."<br>\n";
exit;
}
/*Executeaquery*/

www.kaniyam.com

174

$sql_statement="SELECTbook_id,cond,titleFROMbook";
$result=$conn>query($sql_statement);
if(!$result){
echo"Errorexecutingquery:Error:".
$conn>error()."<br>\n";
exit;
}
/*Loopthroughtheresultsettodisplayit*/
echo"<table>\n";
while($row=$result>fetch_array()){
echo"<tr>\n";
for($i=0;$i<$result>num_rows;$i++){
echo"<td>".$row[$i]."</td>\n";
}
echo"</tr>\n";
}
echo"</table>";
?>

www.kaniyam.com

175

15 Backup Trouble Shooting

MySQL Server-
.
.
15.1 Backup
database-
.
, data- , backup
file- data-
.
database- backup
.
database- update backup
database- offline-
.
backup . Full
backup Incremental backup .
.
15.2 Full Backup
database- sql file-
backup mysqldump command .
database- table- create statement-,
table- row- insert statement
sql file- .

www.kaniyam.com

176

mysqldump command output-


. output- file- redirect
backup file- .
mysqldumpuser=userhost=hostport=port\
password=passworddbname>filename.sql
mysqldump command-
, database- backup
database- .
database- table-
, table- backup .
, database- tables
, tables backup .
library database- book
person tables tables
library.sql file- backup . command
'shell' prompt- run .
mysqldumpuser=root\
password=muralilibrarybookperson>library.sql;

command- host port options-


. command, local machine- default
port- .
databases- backup
databases switch- , backup
databases- . .
www.kaniyam.com

177

mysqldumpuser=rootpassword=murali\
databaseslibraryexams>dump.sql

, MySQL server- databases-


backup all-databases switch .
15.3 Incremental backup
database- backup
. full backup , database-
tables table- rows
mysqldump command- .
busy- server- performance
.
Incremental backup .
Incremental backup- MySQL server restart
FLUSH LOGS command
binary logging feature binary log
.

www.kaniyam.com

178

binary logging feature- enable log_bin option- my.cnf


file- , MySQL server- restart mysqld- -log-bin
switch- .
binary log- user- home directory-
/var/lib/mysql , hostname-bin.XXX
. hostname server-
, XXX .
MySQL server restart
FLUSH LOGS command-
binary log .
binary log- update data- SQL query-
. update, Insert delete
statement- binary log- .
update statement row- update
statement log- .
database- full
backup- database backup
.
binary log- full backup
transactions- . binary log- backup file-
synchronize , mysqldump command- --flush-logs
option- . dump FLUSH LOGS command-
. database-
binary log- .
binary logs- server- performance
performance .
MySQL documentation- binary logging, enable server-
performance

www.kaniyam.com

179

15.4 Backup- restore


database-
, backup file-
restore .
15.5 Full backup- restore

mysqluser=userhost=hostport=port\
password=passworddbname<filename.sql

backup file- MySQL


command- input file- database-
restore
backup database-
backup file- restore , database-
tables overwrite .
mysqldump- output-, backup table-
Drop Table statement- .
database- backup file- Create Database
statement- . file-
restore MySQL command- database-
database- restore
.
database- backup file- mysqldump command-
--all-databases --databases option-
. file- database- Create
Database command
15.6 Incremental Backup- restore
database- Incremental backup- restore ,
full backup- restore .
www.kaniyam.com

180

database- binary log files-


restore .
mysqlbinlog utility . utility binary
log format- backup file- sql commands- text
format- . mysqlbinlog- output MySQL
command- input- .
mysqlbinloghostnamebin.XXX|mysqloptionsdbname
command- output- command- input-
pipe- file re-direction .
command, database- binary log file-
regular expression- command- restore
.
mysqlbinloghostnamebin.[09]*|\
mysqloptionsdbname
regular expression, format-
file-, command MySQL-
input- . file name-
0- , command file-
read . binary log
files- manual- restore ,
file- .
15.7 Table- corrupt- data-
MySQL data files- corrupt repair
. table
CHECK TABLE command-
. syntax .

www.kaniyam.com

181

CHECKTABLEtable;
REPAIRTABLEtable;
command, book table- error
.
CHECKTABLEbook;
command- output , table
. table-
.

output- msg_text column- check


table- error error- .
error REPAIR TABLE
command MySQL error- .
MySQL- myisamchk utility, MyISAM tables- SQL
commands- .
myisamchk command option- run ,
table- error .
Command line switches-
.

www.kaniyam.com

182

myisamchk utility- MyISAM table files


data directory- .MYI file extension-
. data directory- /var/lib/mysql,
sampdb database- tables command
.
myisamchk/var/lib/mysql/sampdb/*.MYI
command- --fast switch-
tables- . tables
.
--medium-check option
table- errors-
. --medium-check option-
--extend-check
command . option
, table-
.
switches- , table file
corrupt , --recover switch
.
mysqld- .
data- MySQL server- repair file-
.
--recover switch data file- error-
, --safe-recover switch
. error-

15.8 Server Crash-


MySQL
server- crash . server
crash- bug report - .
.

www.kaniyam.com

183

crash MySQL server


client . ,
mysqladminversion
command- run . UP-
. OUTPUT .

Uptime:4days8hours20min3sec
output- server- UP
. server client-
client program- .
output- UP time
mysqld crash- ,
tables corrupt-
. mysqld - command- data
directory- run .

www.kaniyam.com

184

myisamchksilentforce*/*.MYI
system- table- .
mysqld- --log switch- restart , my.cnf
file- [mysqld] log- . execute
sql command- file- log .
commands- crash-
.
http://bugs.mysql.com/ bug database- query
, bug report- file .
crash- server- .
system- RAM- hard drives-
MySQL- crash- . server
crash- system-
hardware- .
15.9 ERRORS
errors-
.
Can' t Connect to MySQL Server
error, server machine- mysqld process
.
ERROR2002:Can'tconnecttolocalMySQLserver
throughsocket'/var/lib/mysql/mysql.sock'(2)
ERROR2003(HY000):Can'tconnecttoMySQLserver
on'123.45.67.89'(113)

www.kaniyam.com

185

local MySQL server- ,


system- process list- . Linux- ps -ax
command-, Windows- Task Manager command-, system-
process- . mysqld process
, MySQL server- start .
, socket file
. socket file, /tmp/mysql.sock
. systems /tmp

. /tmp user
. mysql.sock
file- .
socket file- MySQL user- directory-
.
my.cnf file- .
[mysqld]
socket=/path/to/mysql.sock
[client]
socket=/path/to/mysql.sock
Port- mysqld network
Unix/Linux- command
.
shell>netstatltnp|grep3306

www.kaniyam.com

186

windows- .
>netstata|find"LISTENING"
remote MySQL server- ,
mysqld- firewall
settings- . Port 3306 port
port- TCP/IP traffic- .
error message "MySQL server-
" " "
. MySQL server-
password- "
" error .
Access Denied
username password
database- username
error .
ERROR1045(28000):Accessdeniedforuser
'user'@'host'(usingpassword:YES)
MySQL database- privilege table- ,
connection arguments-

--password -p switch-
password- .
-p- argument database name
.
Too Many Connections

www.kaniyam.com

187

MySQL-
max_connections variable- .
100 . 100-
error
.
ERROR1040:Toomanyconnections
variable- my.cnf file-
errors- .
[mysqld]
max_connections=200
. MySQL,

. system
max_connections-
.
variable-
. superuser-
.
super user-
.
mysqladmin processlist command-
.
MySQL Server Has Gone Away
mysqld- client-
error .
ERROR2006:MySQLserverhasgoneaway
8
. wait_timeout system variable-
. variable- seconds-
www.kaniyam.com

188

. error,
mysql program
.
error , mysqld process
. mysql- , mysqld
.
Got Error from Table Handler
error database- table storage file- .
Error1030:Goterror141fromtablehandler
myisamchk utility-
. message- error ,
. error perror command
error message- .
shell>perror141
141=Duplicateuniquekeyorconstraintonwrite
orupdate
error myaqld-
myisamchk -- recover .MYI file- run .
error message, system
. .
$perror28
Errorcode28:Nospaceleftondevice

15.10

.
www.kaniyam.com

189

http://dev.mysql.com/doc/refman/5.0/en/temp0105.html
online manual-
.
MySQL mailing list- topics-
. lists-
.
mailing list- http://lists.mysql.com/
.
MySQL
AB- . MySQL AB ,
support- . support packages-
MySQL knowledge base- .
MySQL Knowledge base
technical articles- searchable
library
24 , 7 support
.
MySQL expert , remote-
.
www.mysql.com/support/ .

www.kaniyam.com

190

16



.
, , .
.

.
, ,
.

.
.

.
editor@ kaniyam. com


.
:

www.kaniyam.com

191



.

.
, .

.
,
.
.
, , , , ,

.
.
editor@kaniyam.com
.
,
.
editor@kaniyam.com .


.

.

www.kaniyam.com

192


.
.

.


2013 .

http://creativecommons.org/licenses/by-sa/3.0/
.
,

, , , ,
, .
: . editor@kaniyam.com +91 98417 95468
: . , 13 11 , ,
600035 . : +91 94455 54009 amachu@kaniyam.com
.

www.kaniyam.com

193

www.kaniyam.com

You might also like