• 11.1 LAMP架构介绍 11.2 MySQL、MariaDB介绍 11.3/11.4/11.5 MySQL安装


    11.1 LAMP架构介绍

    •  Linux + Apache(httpd)+ MySQL + PHP mark

    •  PHP网站(Google、淘宝、百度、51cto博客、猿课论坛)

    •  三个角色可以在一台机器、也可以分开(httpd和PHP要在一起)

    • LAMP架构介绍

    • httpd 、 PHP 、MySQL 三者如何工作 mark

    • Apache(httpd)和 PHP是一个整体 (PHP是以一个模块的形式和Apache结合在一起)

    • 但是Apache不能直接和MySQL 相互打交道,等通过PHP 模块,去MYSOL 里面拿数据,PHP把结果交给给apche ,apache 再交给用户,这样的一个过程,这种php 和 mysql 相连取数据的操作行为,叫做动态行为

    • 访问一个网站,首先要登录,在登录的时候,这样的一个过程,在浏览器里输入网址,点登录,请求交给了apache ,apache 先检查,看下请求是动态还是静态,登录这个行为需要去把你的用户名密码提交给apache,apache拿到你的用户名密码,去数据库里面比对,看看是否正确,通过PHP模块和 mysql 去打交道,通过mysql 查到你的用户名密码是什么,然后php 做对比,看看对不对,如果对,apache 会返回给您一个登录的状态,这个过程属于一个动态的请求

    • 动态请求 比如用户进入猿课论坛输入自己的账号密码

    • 比如访问的图片,网站的logo,比如访问论坛的一个logo, 这个logo 也是需要到apache 上去请求的,apache拿到logo logo 它并没有存在mysql 里面 ,所以直接从静态文件这,也是就是你的linux服务器上 其中的一个目录下拿到这个图片 ,直接返回给用户,这个过程并没有和MySQL打交道,这个过程属于静态请求

    • 静态请求,比如查看网站的图片、内容

    • MySQL里面不能存图片、文件, 可以存一些用户名密码,积分,回复帖子的内容

    11.2 MySQL_MariaDB介绍

    • 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 
    一、支持YUM,则
    yum install -y cmake
    二、也可以源码安装
    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
    ```
     
    - 此时就可以使用新的密码了。
  • 相关阅读:
    editplus设置自动换行方法 editplus自动换行设置步骤
    com.google.gson.stream.MalformedJsonException
    系统架构设计师 笔记1
    微信文档采用第三方方式打开选择qq
    手机不弹toast解决方法
    Excel 如何快速切换到最后一行
    vue系列4:引入插件
    vue系列3:引入css和js
    vue系列2:npm install 命令详解
    vue系列1:创建vue项目
  • 原文地址:https://www.cnblogs.com/pta188/p/9075054.html
Copyright © 2020-2023  润新知