Вы находитесь на странице: 1из 183

.

MySQL 5

MySQL 5

:
 MySQL 5
 MySQL 5
 MySQL 5



:
 MySQL 5
 ,

MySQL 5

MySQL 5

MySQL 5

MySQL 5

MySQL 5

MySQL 5

MySQL 5

MySQL 5

10

MySQL 5

11

MySQL 5

12

MySQL 5

13

MySQL 5

14

MySQL 5

15

MySQL 5

16

MySQL 5

17

MySQL 5

 CD

 CD_drive:\Soft\MySQL
MySQL 5

setup.exe
 ,
MySQL
 , MySQL ,
TCP 3306 (
netstat ano)

18

MySQL 5

19

MySQL 5

20

MySQL 5

21

MySQL 5

22

MySQL 5

23

MySQL 5

 :
  cmd

mysql uroot ppassword

USE mysql;

SHOW TABLES;
 user
SELECT * FROM user\G

24

26

27

28

29

30

31

32

33

34

35

36

37

38

:
o


o

(, e-mail)

()

39

40

41

42

43

44

45

46

()

47

48

SQL:

SQL:

50

SQL:

51

SQL:

52

SQL:

53

SQL:

54

SQL:

55

SQL:

56

SQL:

57

SQL:

58

SQL:

59

SQL:

60

(
course_db.xls
( )

SQL:

61

SQL:

62

SQL:

63

SQL:

INFORMATION_SCHEMA
use INFORMATION_SCHEMA;


show tables;


describe table_name;

64

SQL:

65

SQL:

66

SQL:

67

SQL:

68

SQL:

69

SQL:

courses
lessons.teacher
lessons.course
lessons.date
courses.cathegory
courses.previous

70

SQL:

71

SQL:

72

SQL:

73

SQL:

74

SQL:

75

SQL:

76

SQL:

77

SQL:

78

SQL:

79

SQL:

course_db.sql


mysql uroot ppassword course < course_db.sql


mysql uroot ppassword course

:
set names 'cp866';

80

SQL:

81

SQL:

82

SQL:

SQL:

84

SQL:

85

SQL:

86

SQL:

87

SQL:

88

SQL:

89

SQL:

90

SQL:

91

SQL:

92

SQL:

courses

,
lessons -19

,
21.09.2006

93

SQL:

94

SQL:

95

SQL:

96

SQL:

97

SQL:

98

courses

,
-19

SQL:

99

SQL:

100

SQL:

101

SQL:

102

SQL:

103

SQL:

104

SQL:

courses

, ,

, ,
10.09.2006

105

SQL:

106

108

109

110

111

112

113

world

, world
CREATE DATABASE world;

MySQL
quit


mysql uroot ppassword world < world.sql

MySQL world
mysql uroot ppassword world

114

,
10 000 000

,
1 000 000
- 5 000 000

115

116

117

118

world

(
)

INFORMATION_SCHEMA,
world

119

120

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

world,

143

144

145

146

course

teachers,

,
lessons
course

147

148


MySQL


MySQL

150


MySQL

151


MySQL

152


MySQL

153


MySQL

154


MySQL

155


MySQL

156


MySQL

157


MySQL

158


MySQL



mysql -uroot -ppassword course


set names 'cp866';

(, )

start transaction;


insert into courses (title)
values (' ');

( )

select title from courses;

159


MySQL


rollback;

SET TRANSACTION ISOLATION LEVEL READ


UNCOMMITTED;

start transaction;

insert into courses (title)


values (' ');
( )

select title from courses;


rollback;
( )

select title from courses;

160

READ UNCOMMITTED

READ COMMITTED

REPEATABLE READ

SERIALIZABLE


MySQL

161


MySQL

162


MySQL

163


MySQL

test
USE test;

city1 city2
city world
CREATE TABLE city1 LIKE world.city;
CREATE TABLE city2 LIKE world.city;

id city1
ALTER TABLE city1 DROP COLUMN id;

id ( AUTO_INCREMENT!)
city1
ALTER TABLE city1 ADD COLUMN id INT;

city1
ALTER TABLE city1 ENGINE=ARCHIVE;


mysql>
->
->
->

164

city1 city
world

INSERT INTO city1


(id, Name, CountryCode, District, Population)
SELECT id, Name, CountryCode, District, Population
FROM world.city;


MySQL


city2
ALTER TABLE city2 ENGINE=MEMORY;

city2 city
world
INSERT INTO city2 SELECT * FROM world.city;

mysql> SELECT name, population FROM city1


-> WHERE name LIKE '%os%'
-> ORDER BY population;
mysql> SELECT name, population FROM city2
-> WHERE name LIKE '%os%'
-> ORDER BY population;



test

city2
ALTER TABLE city2 ENGINE=MyISAM;

165


MySQL

166



MySQL 5


MySQL 5

168


MySQL 5

169


MySQL 5

170


MySQL 5

171


MySQL 5


cd C:\MySQL-course


world
mysqldump -uroot -ppassword world > world.sql

C:\MySQL-course\world.sql
Windows.


course
mysqldump -uroot -ppassword course >
course.sql

172

C:\MySQL-course\course.sql
Windows.

ANSI,
BOM (Byte Order Mark)


MySQL 5

SET NAMES 'cp1251';


world.sql
( world ,
)

world course

mysql -uroot -ppassword -e "drop database course"


mysql -uroot -ppassword -e "drop database world"


world course

mysql -uroot -ppassword -e "create database course"


mysql -uroot -ppassword -e " create database world"


mysql -uroot -ppassword course < course.sql


mysql -uroot -ppassword world < world.sql


, :
mysql -uroot -ppassword course
mysql> SET NAMES 'cp866';
mysql> select * from teachers;

world

173


MySQL 5

174


MySQL 5

175


MySQL 5

176


MySQL 5

177


MySQL 5

178


MySQL 5

179


MySQL 5

180


MySQL 5


mysql -uroot -ppassword world


mysql>
->
->
->
->
->

SELECT name, population


FROM city
WHERE id IN (
SELECT id FROM city
WHERE population > 1000000)
ORDER BY population;


mysql>
->
->
->
->
->

EXPLAIN SELECT name, population


FROM city
WHERE id IN (
SELECT id FROM city
WHERE population > 1000000)
ORDER BY population;



, ?

my.ini


query_cache_size=1M
181


MySQL 5

my.ini


MySQL quit

MySQL
net stop mysql
net start mysql

world
mysql -uroot -ppassword world

SHOW VARIABLES LIKE 'query_cache%';


mysql>
->
->
->
->
->

SELECT name, population


FROM city
WHERE id IN (
SELECT id FROM city
WHERE population > 1000000)
ORDER BY population;


182


MySQL 5

183