Loading

MySQL安装

  1. 解压安装包

    [root@localhost home]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 
    [root@localhost /]# mkdir /application
    [root@localhost home]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql
    
  2. 删除centos自带的mariadb数据库

    [root@localhost home]# rpm -qa | grep mariadb	//检查安装的mariadb版本
    mariadb-libs-5.5.56-2.el7.x86_64
    [root@localhost home]# yum remove mariadb-libs-5.5.56-2.el7.x86_64 -y
    
  3. 创建用户

    [root@localhost ~]# useradd -s /sbin/nologin mysql
    [root@localhost ~]# id mysql
    uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
    
  4. 设置环境变量

    [root@localhost ~]# vi /etc/profile
    export PATH=/application/mysql/bin:$PATH	
    [root@localhost ~]# source /etc/profile
    [root@localhost ~]# mysql -V
    mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper
    
  5. 授权

    [root@localhost /]# chown -R mysql.mysql /application/*
    [root@localhost /]# mkdir /data
    [root@localhost /]# chown -R mysql.mysql /data
    
  6. 初始化数据库

    5.6 版本初始化命令
    /application/mysql/scripts/mysql_install_db
    5.7 版本初始化命令
    [root@localhost ~]# mkdir -p /data/mysql/data
    [root@localhost ~]# chown -R mysql.mysql /data
    [root@localhost ~]# mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data
    
    2020-07-04T08:20:40.457712Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-07-04T08:20:41.084761Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-07-04T08:20:41.167569Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-07-04T08:20:41.235455Z 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: 3fac3cb9-bdcf-11ea-b8e1-000c290aadee.
    2020-07-04T08:20:41.237823Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-07-04T08:20:41.241061Z 1 [Note] A temporary password is generated for root@localhost: IPbDdP_r<6d% //用户的临时密码
    
    注:--initialize 参数
    1.对于密码复杂度进行定制:12位,4种字符
    2.密码过期时间:180
    3.给root@localhost用户设置临时密码
    
    --initialize-insecure 参数
    无限制,无临时密码
    [root@localhost ~]# \rm -rf /data/mysql/data/*  //删除之前的初始化配置
    [root@localhost ~]# mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data
    
  7. 准备配置文件

    cat >/etc/my.cnf <<EOF
    [mysqld]
    user=mysql
    basedir=/application/mysql
    datadir=/data/mysql/data
    socket=/tmp/mysql.sock
    server_id=6
    port=3306
    [mysql]
    socket=/tmp/mysql.sock
    EOF
    
  8. 启动数据库

    两种方式
    1.sys-v
    [root@localhost ~]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
    [root@localhost ~]# service mysqld start
    Starting MySQL.Logging to '/data/mysql/data/localhost.localdomain.err'.
    . SUCCESS! 
    
    2.systemd
    注意:sysv方式启动过的话,需要先提前关闭,才能以下方式登录
    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
    //此处修改mysqld路径
    LimitNOFILE=5000
    EOF
    
posted @ 2020-07-04 17:09  北兢王  阅读(173)  评论(0)    收藏  举报