Linux + Apache(httpd)+ MySQL + PHP php
PHP網站(Google、淘寶、百度、51cto博客、猿課論壇)html
三個角色能夠在一臺機器、也能夠分開(httpd和PHP要在一塊兒)mysql
LAMP架構介紹linux
httpd 、 PHP 、MySQL 三者如何工做 sql
Apache(httpd)和 PHP是一個總體 (PHP是以一個模塊的形式和Apache結合在一塊兒)數據庫
可是Apache不能直接和MySQL 相互打交道,等經過PHP 模塊,去MYSOL 裏面拿數據,PHP把結果交給給apche ,apache 再交給用戶,這樣的一個過程,這種php 和 mysql 相連取數據的操做行爲,叫作動態行爲apache
訪問一個網站,首先要登陸,在登陸的時候,這樣的一個過程,在瀏覽器裏輸入網址,點登陸,請求交給了apache ,apache 先檢查,看下請求是動態仍是靜態,登陸這個行爲須要去把你的用戶名密碼提交給apache,apache拿到你的用戶名密碼,去數據庫裏面比對,看看是否正確,經過PHP模塊和 mysql 去打交道,經過mysql 查到你的用戶名密碼是什麼,而後php 作對比,看看對不對,若是對,apache 會返回給您一個登陸的狀態,這個過程屬於一個動態的請求bootstrap
動態請求 好比用戶進入猿課論壇輸入本身的帳號密碼vim
好比訪問的圖片,網站的logo,好比訪問論壇的一個logo, 這個logo 也是須要到apache 上去請求的,apache拿到logo logo 它並無存在mysql 裏面 ,因此直接從靜態文件這,也是就是你的linux服務器上 其中的一個目錄下拿到這個圖片 ,直接返回給用戶,這個過程並無和MySQL打交道,這個過程屬於靜態請求瀏覽器
靜態請求,好比查看網站的圖片、內容
MySQL裏面不能存圖片、文件, 能夠存一些用戶名密碼,積分,回覆帖子的內容
MySQL是一個關係型數據庫,由mysql ab公司開發,mysql在2008年被sun公司收購(10億刀),2009年sun公司被oracle公司收購(74億刀)
MySQL官網https://www.mysql.com 最新版本5.7GA/8.0DMR
MySQL5.6變化比較大,5.7性能上有很大提高
Mariadb爲MySQL的一個分支,官網https://mariadb.com/最新版本10.2
MariaDB主要由SkySQL公司(現改名爲MariaDB公司)維護,SkySQL公司由MySQL原做者帶領大部分原班人馬創立.
Mariadb5.5版本對應MySQL的5.5,10.0對應MySQL5.6 Community 社區版本,Enterprise 企業版,GA(Generally Available)指通用版本,在生產環境中用的,DMR(Development Milestone Release)開發里程碑發佈版,RC(ReleaseCandidate)發行候選版本,Beta開放測試版本,Alpha內部測試版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
11.3 MySQL 安裝 (上)
- MySQL的幾個經常使用安裝包:rpm、源碼、二進制免編譯
- 二進制免編譯(發佈以前在linux服務器上租了一個編譯,編譯完了以後,把編譯完成的文件從新安排,放到一個目錄下去,而後打包壓縮,發佈)有一個好處,不用花那麼多時間去配置,直接拿來用就能夠
- rpm 包有一個缺點,沒有辦法去定義你所安裝的路徑,默認就安裝在 /usr 下
- 二進制免編譯包能夠放在一個目錄下,好比說 /urs/local/src 下,也能夠放在別的目錄下,隨便你本身
- 二進制免編譯包畢竟在其餘編輯器上編輯的,若是想追求極致的性能,就本身去編譯
- 若是工做中沒有特殊的要求,能夠用二進制免編譯包就能夠。
- 先進入到目錄 /usr/local/src
```
[root@aminglinux-001 ~] # cd /usr/local/src/
[root@aminglinux-001 src] # ls
httpd-2.4.27 httpd-2.4.27. tar .gz
```
- 用命令 uname -a 查看當前系統版本,x86_64 這個是64位的
- 能夠去r.aminglinux.com 下載地址 ,咱們這邊下載5.6_64位二進制包
```
[root@aminglinux-001 src] # uname -a
Linux aminglinux-001 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@aminglinux-001 src] #
```
- 使用wget下載
```
[root@aminglinux-001 src] # wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2
--2017-09-19 23:06:16-- http: //mirrors .sohu.com /mysql/MySQL-5 .6 /mysql-5 .6.35-linux-glibc2.5-x86_
正在解析主機 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140
正在鏈接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已鏈接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:314581668 (300M) [application /octet-stream ]
正在保存至: 「mysql-5.6.35-linux-glibc2.5-x86_64. tar .gz」
12% [============> 100%[======================================================>] 314,581,668 486KB /s 用時 18m 3s
2017-09-19 23:24:19 (284 KB /s ) - 已保存 「mysql-5.6.35-linux-glibc2.5-x86_64. tar .gz」 [314581668 /314581668 ])
[root@aminglinux-001 src] #
```
11.4 MySQL 安裝 (中)
- 下載完以後第一步是要解壓,
```
[root@aminglinux-001 src] # ls
httpd-2.4.27 httpd-2.4.27. tar .gz mysql-5.6.35-linux-glibc2.5-x86_64. tar .gz
[root@aminglinux-001 src] # tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
.
.
.
mysql-5.6.35-linux-glibc2.5-x86_64 /mysql-test/include/stop_slave .inc
mysql-5.6.35-linux-glibc2.5-x86_64 /mysql-test/mysql-test-run .pl
mysql-5.6.35-linux-glibc2.5-x86_64 /mysql-test/purify .supp
mysql-5.6.35-linux-glibc2.5-x86_64 /mysql-test/valgrind .supp
```
- 挪目錄到 local 目錄下 而且更名mysql(mysql也是目錄), mv /usr/local/mysql ,而後到mysql目錄下
```
[root@aminglinux-001 src] # mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
[root@aminglinux-001 src] # cd /usr/local/mysql/
[root@aminglinux-001 mysql] # ls
bin data include man README share support-files
COPYING docs lib mysql- test scripts sql-bench
[root@aminglinux-001 mysql] #
```
- 建立mysql用戶,建立目錄 /data/
```
[root@aminglinux-001 mysql] # useradd mysql
[root@aminglinux-001 mysql] # mkdir /data/
mkdir : 沒法建立目錄 "/data/" : 文件已存在
[root@aminglinux-001 mysql] # ls /data/
liurongluan
[root@aminglinux-001 mysql] #
```
- 運行. /scripts/mysql_install_db --user=mysql --datadir= /data/mysql 初始化
```
[root@aminglinux-001 mysql] # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing . /scripts/mysql_install_db :
Data::Dumper
[root@aminglinux-001 mysql] #
```
- 如今報錯了, please install the following Perl modules before executing 提示少了一個perl模塊,名字是Dumper,嘗試搜索一下
```
[root@aminglinux-001 mysql] # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing . /scripts/mysql_install_db :
Data::Dumper
[root@aminglinux-001 mysql] # yum list |grep perl |grep -i dumper
perl-Data-Dumper.x86_64 2.145-3.el7 base
perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel
perl-Data-Dumper-Names.noarch 0.03-17.el7 epel
perl-XML-Dumper.noarch 0.81-17.el7 base
[root@aminglinux-001 mysql] #
```
- 安裝第四個試下 perl-XML-Dumper
```
[root@aminglinux-001 mysql] # yum install -y perl-XML-Dumper
已加載插件:fastestmirror
base | 3.6 kB 00:00:00
epel /x86_64/metalink
已安裝:
perl-XML-Dumper.noarch 0:0.81-17.el7
做爲依賴被安裝:
perl-XML-Parser.x86_64 0:2.41-10.el7
完畢!
[root@aminglinux-001 mysql] # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing . /scripts/mysql_install_db :
Data::Dumper
[root@aminglinux-001 mysql] #
```
- 仍是不行,再試下第一個包 perl-Data-Dumper
```
[root@aminglinux-001 mysql] # yum install -y perl-Data-Dumper
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.tuna.tsinghua.edu.cn
已安裝:
perl-Data-Dumper.x86_64 0:2.145-3.el7
完畢!
[root@aminglinux-001 mysql] # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2017-09-23 13:01:36 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-23 13:01:36 0 [Note] Ignoring --secure- file -priv value as server is running with --bootstrap.
2017-09-23 13:01:36 0 [Note] . /bin/mysqld (mysqld 5.6.35) starting as process 2630 ...
2017-09-23 13:01:36 2630 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-09-23 13:01:36 2630 [Note] InnoDB: The InnoDB memory heap is disabled
Support MySQL by buying support /licenses at http: //shop .mysql.com
New default config file was created as . /my .cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my .cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults- file argument to mysqld_safe when starting the server
[root@aminglinux-001 mysql] #
```
- 能夠了,怎麼查看一個命令執行完後 是否正確? 再上一個命令運行完以後 echo $? 結果是0 就是正確的,是1就是錯誤的
```
[root@aminglinux-001 mysql] # echo $?
0
[root@aminglinux-001 mysql] #
```
- 初始化完成,下面就是拷貝配置文件和啓動腳本,配置文件在哪?在這個目錄下support-files/
```
[root@aminglinux-001 mysql] # ls support-files/
binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@aminglinux-001 mysql] #
[root@aminglinux-001 mysql] # ls support-files/my-default.cnf
support-files /my-default .cnf
```
- 這裏面大部分都是註釋文件
```
[root@aminglinux-001 mysql] # vi support-files/my-default.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
"support-files/my-default.cnf" 31L, 1126C
```
- 下面就是拷貝配置文件和啓動腳本
```
[root@aminglinux-001 mysql] # cp support-files/my-default.cnf /etc/my.cnf^C
```
- 拷貝以前 也能夠看下系統自帶的my.cnf 文件,要用自帶的my.conf 須要修改裏面配置文件
```
[root@aminglinux-001 mysql] # ls /etc/my.cnf
/etc/my .cnf
[root@aminglinux-001 mysql] # rpm -qf /etc/my.cnf
mariadb-libs-5.5.52-1.el7.x86_64
[root@aminglinux-001 mysql] #
[root@aminglinux-001 mysql] # vim /etc/my.cnf
[mysqld]
datadir= /var/lib/mysql
socket= /var/lib/mysql/mysql .sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error= /var/log/mariadb/mariadb .log
pid- file = /var/run/mariadb/mariadb .pid
#
# include all files from the config directory
```
- 須要修改 /etc/my .cnf 用默認的配置文件
```
[mysqld]
datadir= /data/mysql
socket= /tmp/mysql/mysql .sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
~
:wq
```
- 再一個就是它的啓動腳本
```
[root@aminglinux-001 mysql] # ls
bin data include man mysql- test scripts sql-bench
COPYING docs lib my.cnf README share support-files
[root@aminglinux-001 mysql] #
```
11.5 MySQL 安裝 (下)
- 再一個就是它的啓動腳本
```
[root@aminglinux-001 mysql] # ls
bin data include man mysql- test scripts sql-bench
COPYING docs lib my.cnf README share support-files
[root@aminglinux-001 mysql] #
[root@aminglinux-001 mysql] # ls support-files/
binary-configure my-default.cnf mysql-log-rotate
magic mysqld_multi.server mysql.server
```
- 把support-files /mysql .server腳本 拷貝到 更名 /etc/init .d /mysqld
```
[root@aminglinux-001 mysql] # cp support-files/mysql.server /etc/init.d/mysqld
[root@aminglinux-001 mysql] #
[root@aminglinux-001 mysql] # vi /etc/init.d/mysqld
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=
datadir=
-- INSERT --
```
- 改下basedir datadir
```
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir= /usr/local/mysql
datadir= /data/mysql
:wq
```
- 看下權限是755
```
[root@aminglinux-001 mysql] # vi /etc/init.d/mysqld
[root@aminglinux-001 mysql] # ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10902 9月 23 13:27 /etc/init .d /mysqld
[root@aminglinux-001 mysql] #
```
- 若是想讓它開機啓動,須要把它加入到系統服務列表裏去 下次開機會自動啓動
```
[root@aminglinux-001 mysql] # chkconfig --add mysqld
[root@aminglinux-001 mysql] # chkconfig --list
注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
若是您想列出 systemd 服務,請執行 'systemctl list-unit-files' 。
欲查看對特定 target 啓用的服務請執行
'systemctl list-dependencies [target]' 。
mysqld 0:關 1:關 2:開 3:開 4:開 5:開 6:關
netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:關 4:關 5:關 6:關
[root@aminglinux-001 mysql] #
```
- 一樣的,也能夠直接用命令把它啓動起來
/etc/init .d /mysql start
- 也能夠這樣service mysqld start
```
[root@aminglinux-001 mysql] # ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10875 9月 23 18:13 /etc/init .d /mysqld
[root@aminglinux-001 mysql] # chmod 755 /etc/init.d/mysqld
[root@aminglinux-001 mysql] # vim /etc/init.d/mysqld
[root@aminglinux-001 mysql] # chkconfig --add mysqld
[root@aminglinux-001 mysql] # chkconfig mysqld on
[root@aminglinux-001 mysql] # service mysqld start
Starting MySQL.Logging to '/data/mysql/aminglinux-001.err' .
.. SUCCESS!
[root@aminglinux-001 mysql] #
```
- 查看下服務 是否有,看下進程
```
[root@aminglinux-001 mysql] # ps aux |grep mysql
root 6110 0.0 0.1 11764 1580 pts /0 S 18:15 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir= /data/mysql --pid- file = /data/mysql/aminglinux-001 .pid
mysql 6320 0.8 45.6 973052 456580 pts /0 Sl 18:15 0:01 /usr/local/mysq/bin/mysqld --basedir= /usr/local/mysql --datadir= /data/mysql --plugin- dir = /usr/local/mysql/lib/plugin --user=mysql --log-error= /data/mysql/aminglinux-001 .err --pid- file = /data/mysql/aminglinux-001 .pid --socket= /tmp/mysql .sock --port=3306
root 6386 0.0 0.0 112664 976 pts /0 S+ 18:19 0:00 grep --color=auto mysql
[root@aminglinux-001 mysql] # netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1131 /sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1648 /master
tcp6 0 0 :::3306 :::* LISTEN 6320 /mysqld
tcp6 0 0 :::22 :::* LISTEN 1131 /sshd
tcp6 0 0 ::1:25 :::* LISTEN 1648 /master
[root@aminglinux-001 mysql] #
```
- 若是說有一天你沒有辦法把啓動腳本放到 /etc/init .d/ 下去,或者說你根本就沒有這樣的啓動模板去拷貝,能夠用這種方法去啓動
- 首先咱們先給mysqld 停掉
```
[root@aminglinux-001 mysql] # service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@aminglinux-001 mysql] # !ps
ps aux | grep mysql
root 6427 0.0 0.0 112664 972 pts /0 S+ 18:23 0:00 grep --color=auto mysql
```
- 使用這種方法命令行的方式啓動
```
[root@aminglinux-001 mysql] # /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[2] 6716
[1] 完成 /usr/local/mysql/bin/mysqld_safe --default- file = /etc/my .cnf --user=mysql --datadir= /data/mysql
[root@aminglinux-001 mysql] # 170923 18:28:43 mysqld_safe Logging to '/data/mysql/aminglinux-001.err'.
170923 18:28:43 mysqld_safe Starting mysqld daemon with databases from /data/mysql
[root@aminglinux-001 mysql] #
[root@aminglinux-001 mysql] # ps aux |grep mysql
root 6716 0.0 0.1 113256 1584 pts /0 S 18:28 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults- file = /etc/my .cnf --user=mysql --datadir= /data/mysql
mysql 6914 0.5 45.4 973052 454888 pts /0 Sl 18:28 0:00 /usr/local/mysql/binmysqld --defaults- file = /etc/my .cnf --basedir= /usr/local/mysql --datadir= /data/mysql --plugin- dir = /usr/local/mysql/lib/plugin --user=mysql --log-error= /data/mysql/aminglinux-001 .err --pid- file = /data/mysql/aminglinux-001 .pid --socket= /tmp/mysql .sock --port=3306
root 6937 0.0 0.0 112664 976 pts /0 S+ 18:29 0:00 grep --color=auto mysql
[root@aminglinux-001 mysql] #
[root@aminglinux-001 mysql] # netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1131 /sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1648 /master
tcp6 0 0 :::3306 :::* LISTEN 6914 /mysqld
tcp6 0 0 :::22 :::* LISTEN 1131 /sshd
tcp6 0 0 ::1:25 :::* LISTEN 1648 /master
[root@aminglinux-001 mysql] #
```
- 那怎麼去關呢,能夠用killall mysqld 命令 把這個服務停掉
```
[root@aminglinux-001 mysql] # killall mysqld
[root@aminglinux-001 mysql] # 170923 18:32:07 mysqld_safe mysqld from pid file /data/mysql/aminglinux-001.pid ended
[root@aminglinux-001 mysql] # !ps
ps aux | grep mysql
root 6950 0.0 0.0 112664 976 pts /0 R+ 18:32 0:00 grep --color=auto mysq
[2]+ 完成 /usr/local/mysql/bin/mysqld_safe --defaults- file = /etc/my .cnf
[root@aminglinux-001 mysql] #
```
- 建議你們用killall 安全一些,先中止當前的寫讀操做,把那些沒有完成磁盤寫入的數據寫到磁盤裏去,知道寫完以後 才把進程殺死,
- 若是之後遇到 mysqld 的進程 適中殺不死,等了很久沒有把進程殺死 ps 還有進程,那說明你的數據量很大,正在慢慢的寫入磁盤離去,不要強制用 kill ,很容易致使數據丟失,就慢慢的等就行了,
- mysql 有倆個引擎 一個是innodb 一個是 myisam(存儲量比較小)
## 擴展
- mysql5.5源碼編譯安裝 http: //www .aminglinux.com /bbs/thread-1059-1-1 .html
- MYSQL5.5源碼安裝 linux下 ,首先安裝必要的庫
```
yum -y install gcc*
###### 安裝 MYSQL ######
首先安裝camke
1、支持YUM,則
yum install -y cmake
2、也能夠源碼安裝
cd /usr/local/src
#下載cmake
wget http: //www .cmake.org /files/v2 .8 /cmake-2 .8.7. tar .gz
tar zxvf cmake-2.8.7. tar .gz
cd cmake-2.8.7
#安裝cmake
. /configure
make
make install
安裝 MYSQL
官網下載 MYSQL5.5版本 linux下源碼包
http: //dev .mysql.com /downloads/
安裝
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.2.25. tar .gz
cd mysql-5.2.25
#cmake . //默認狀況下安裝,安裝目錄爲/usr/local/mysql 數據目錄爲/usr/local/mysql/data
#也能夠指定參數安裝,如指定UTF8,數據引擎等
#具體參照http://dev.mysql.com/doc/refman/ ... ration-options.html
cmake -DCMAKE_INSTALL_PREFIX= /usr/local/mysql -DMYSQL_DATADIR= /mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL= yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
make && make install
cd /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
. /scripts/mysql_install_db --user=mysql -datadir= /mysql/data
#此處如不指定datadir,到啓動時會報錯
chown -R root .
chown -R mysql data
cp support-files /my-medium .cnf /etc/my .cnf
bin /mysqld_safe --user=mysql &
# Next command is optional
cp support-files /mysql .server /etc/init .d /mysqld
chmod +x /etc/init .d /mysqld
/etc/init .d /mysqld start
```
到此,安裝完成
- mysql5.7二進制包安裝(變化較大) http: //www .apelearn.com /bbs/thread-10105-1-1 .html
- mysql5.7 二進制包安裝
```
1. 下載包
wget http: //mirrors .sohu.com /mysql/MySQL-5 .7 /mysql-5 .7.12-linux-glibc2.5-x86_64. tar .gz
若該連接失效,請到r.aminglinux.com 找最新的下載地址。
2. 解壓
tar xxvf mysql-5.7.12-linux-glibc2.5-x86_64. tar .gz
mv mysql-5.7.12-linux-glibc2.5-x86_64 /usr/local/mysql
3. 初始化
useradd -M -s /sbin/nologin mysql
mkdir -p /data/mysql
chown mysql /data/mysql
cd /usr/local/mysql
. /bin/mysqld --initialize --user=mysql --datadir= /data/mysql
注意,這一步最後一行會有一個提示
[Note] A temporary password is generated for root@localhost: B*s1i(*,kXwg
最後面的字符串爲root密碼。
. /bin/mysql_ssl_rsa_setup --datadir= /data/mysql
4. 拷貝配置文件和啓動腳本
cp support-files /my-default .cnf /etc/my .cnf
vim /etc/my .cnf // 編輯或者修改
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql .sock
cp support-files /mysql .server /etc/init .d /mysqld
vi /etc/init .d /mysqld // 編輯或者修改
basedir= /usr/local/mysql
datadir= /data/mysql
5. 啓動服務
/etc/init .d /mysqld start
6. 設置root密碼
使用初始化密碼登陸
/usr/local/mysql/bin/mysql -uroot -p 'B*s1i(*,kXwg' // 進入後直接設置密碼
mysql> set password = password( 'mypass' ); // 必定要設置一下新密碼
退出來,再使用新的密碼登陸就能夠了
還有一種狀況,就是不知道初始化密碼
vi /etc/my .cnf
在[mysqld]下面增長一行
skip-grant-tables
重啓 /etc/init .d /mysqld restart
/usr/local/mysql/bin/mysql -uroot
mysql> update user set authentication_string=password( '123333' ) where user= 'root' ;
退出來後,更改my.cnf,去掉剛加的 skip-grant-tables
重啓 /etc/init .d /mysqld restart
```
- 此時就可使用新的密碼了。
|