美文网首页
MySQL-简介及安装升级

MySQL-简介及安装升级

作者: 文娟_狼剩 | 来源:发表于2019-08-05 22:26 被阅读0次

    1、 MYSQL介绍

    1>什么是数据?

    图片、文字、视频、用户账户信息、订单等

    2>数据库管理系统(DBMS)
    分为三大类:
    (1)RDBMS(关系型数据库管理系统)
          比较适合于,安全级别要求高的数据以及关系较复杂的数据
    (2)NoSQL(非关系型数据库管理系统)
          适合于高性能存取数据,一般是配合RDBMS进行使用的针对大数据处理分析,分布式架构更加擅长
    (3)NewSQL(分布式型)
    

    常见的关系型数据库和非关系型数据及其区别

    3>MYSQL软件分支

    Oracle的MySQL
    Mariadb
    PerconaDB
    云数据库(RDS MySQL、腾讯DB等)

    4>Oracle的MySQL的企业版本选择

    3.6.1 企业主流版本
    5.6(5.6.34、5.6.36、5.6.38、5.6.40)
    5.7(5.7.18、5.7.19、5.7.20、5.7.24)
    官网下载地址:https://downloads.mysql.com/archives/community/


    注:关于版本GA时间,尽量记录两个版本的具体GA(稳定的发布版)时间(5.6.38 、5.7.20 2017013)
    5>企业版本新环境建议

    上生产使用5.7 版本 (偶数版) GA(稳定的发布版) 6-12 月版本

    2、 MySQL 5.7.26 二进制版规划和部署

    规划:
    1> 硬件环境

    DELL R720 ,CPU28,128G内存 ,RAID108600G(SAS)

    2>系统
    CentOS 7.6
    内核版本 3.10.0-957.el7.x86_64
    3>网络规划
    eth0 10.0.0.51/24
    hostname db01
    4>存储规划

    /dev/sdb

    部署:
    1>创建相关目录
    [root@db01 ~]# mkdir -p /application   #软件的存放目录
    [root@db01 ~]# mkdir /data/3306/data -p   #存放数据的目录
    
    2>创建用户
    [root@db01 ~]# useradd mysql -s /sbin/nologin -M
    [root@db01 ~]# id mysql
    uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)
    [root@db01 ~]# 
    
    3>上传软件并解压处理
    [root@db01 ~]# cd /application/
    [root@db01 /application]# rz -E
    rz waiting to receive.
    [root@db01 /application]# ls
    mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
    [root@db01 /application]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 
    [root@db01 /application]# ls
    mysql-5.7.26-linux-glibc2.12-x86_64  mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
    [root@db01 /application]# ln -s /application/mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql
    [root@db01 /application]# ls
    mysql  mysql-5.7.26-linux-glibc2.12-x86_64  mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
    
    4>数据初始化
    ###注:初始化之前,一定要先删除虚拟机中已有的mariadb
    [root@db01 ~]# rpm -qa|grep mariadb
    mariadb-libs-5.5.60-1.el7_5.x86_64
    [root@db01 ~]# yum remove mariadb-libs-5.5.60-1.el7_5.x86_64
    
    ###配置环境变量
    [root@db01 ~]# vim /etc/profile
    export PATH=/application/mysql/bin:$PATH
    [root@db01 /application]# source /etc/profile
    [root@db01 /application]# mysql -V
    mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper
    [root@db01 /application]# 
    
    [root@db01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/3306/data
    2019-08-05T04:32:18.752279Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2019-08-05T04:32:21.450186Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2019-08-05T04:32:21.538862Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2019-08-05T04:32:21.597721Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0414eb5e-b73a-11e9-ba72-000c290143b9.
    2019-08-05T04:32:21.600866Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2019-08-05T04:32:21.601243Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    [root@db01 ~]# 
    

    遇到的错误:mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
    原因:缺少libaio-devel
    解决:yum install -y libaio-devel即可

    注意:mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/3306/data,作用就是生成数据到/data/3306/data中
    参数说明:
    --initialize-insecure 启用非安全模式,进行数据初始化
    --initialize 启用安全模式,进行数据初始化
    5.7版本以后,加强了用户密码安全管理的功能
    (1)密码长度做了规范
    (2)密码复杂度有要求
    (3)在一次初始化时,总动生成密码

    扩展5.6版本:
    初始化的方式:/application/mysql/scripts/mysql_install_db
    启动方式说明:systemd(CentOS)

    5>书写配置文件
    cat >/etc/my.cnf <<EOF
    [mysqld]
    user=mysql
    basedir=/application/mysql
    datadir=/data/3306/data
    socket=/tmp/mysql.sock
    [mysql]
    socket=/tmp/mysql.sock
    prompt=[\\d]
    EOF
    
    6>准备启动脚本
    chown -R mysql.mysql /data/* /application/mysql/*
    
    [root@db01 /application/mysql/support-files]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
    [root@db01 /application/mysql/support-files]# /etc/init.d/mysqld start
    Starting MySQL.Logging to '/data/3306/data/db01.err'.
     SUCCESS! 
    [root@db01 /application/mysql/support-files]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.7.26 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> 
    

    使用systemctl管理启动mysqld

    cat > /etc/systemd/system/mysqld.service <<EOF
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    LimitNOFILE = 5000
    EOF
    

    3、 同主机版本升级(扩展)

    5.7.36------->8.0.16

    1>备份

    先拍摄快照并备份
    测试的空环境可忽略备份

    2>上传8.0软件包到/application/下进行解压,并创建软连接
    [root@db01 /application]# ls
    mysql                                mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
    mysql-5.7.26-linux-glibc2.12-x86_64  mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
    [root@db01 /application]# tar xf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz 
    [root@db01 /application]# ls
    mysql                                       mysql-8.0.16-linux-glibc2.12-x86_64
    mysql-5.7.26-linux-glibc2.12-x86_64         mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
    mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
    [root@db01 /application]# ln -s /application/mysql-8.0.16-linux-glibc2.12-x86_64 /application/mysql8
    [root@db01 /application]# ls
    mysql                                       mysql8
    mysql-5.7.26-linux-glibc2.12-x86_64         mysql-8.0.16-linux-glibc2.12-x86_64
    mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz  mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
    
    3>停掉原库
    [root@db01 /application]# /etc/init.d/mysqld stop
    Shutting down MySQL.. SUCCESS! 
    [root@db01 /application]# 
    
    4>修改原有的环境变量
    vim /etc/profile
    export PATH=/application/mysql8/bin:$PATH
                                                                        
    [root@db01 /application]# source /etc/profile
    [root@db01 /application]# mysql -V
    mysql  Ver 8.0.16 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
    [root@db01 /application]# 
    
    5>修改配置文件/etc/my.cnf
    [root@db01 /application]# vim /etc/my.cnf 
    [mysqld]
    user=mysql
    #basedir=/application/mysql
    basedir=/application/mysql8
    datadir=/data/3306/data
    socket=/tmp/mysql.sock
    [mysql]
    socket=/tmp/mysql.sock
    
    6>启动脚本
    [root@db01 /application]# /etc/init.d/mysqld start
    Starting MySQL........ SUCCESS! 
    [root@db01 /application]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10
    Server version: 8.0.16 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> 
    

    注:8.0以前的版本,需要进行数据升级(mysql_upgrade),在8.0版本可以省略

    1.4 简单的管理操作

    1>修改root用户密码
    [root@db01 ~]# mysqladmin -uroot -p password 123456
    Enter password: 
    mysqladmin: [Warning] Using a password on the command line interface can be insecure.
    Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
    
    2>查询用户
    mysql> select user,host ,authentication_string from user;
    

    小结:

    • (熟悉)版本选择(5.6 主流版本、5.7 主流版本、GA 6-12)
    • (熟悉)安装方式(rpm安装、二进制安装、源码安装)
    • (重点掌握)规划和部署
    • (了解)升级
    • (熟悉)简单管理

    相关文章

      网友评论

          本文标题:MySQL-简介及安装升级

          本文链接:https://www.haomeiwen.com/subject/xdgvdctx.html