美文网首页
CentOS 7.6安装mysql-5.7.28

CentOS 7.6安装mysql-5.7.28

作者: jackson_wzx | 来源:发表于2020-03-31 14:41 被阅读0次

    1 MySQL下载

    1.1 MySQL官网下载连接

    1.2 选择“Download Archives”。

    GM8Kcn.png

    1.3 选择“MySQL Community”

    GMGwGQ.png

    1.4 Linux版本下载

    GMGOiD.png

    1.5 Windows版本下载

    Snipaste_2020-05-03_08-48-59.png

    2 CentOS 7 MySQL 5.7二进制安装

    2.1 环境准备

    #修改主机名(重启系统生效)
    [root@db1 ~]# vim /etc/hostname
    db1
    #系统版本
    [root@db1 ~]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core)
    #环境检查(MySQL与mariadb冲突,需卸载)
    [root@db1 ~]# rpm -qa|grep mariadb
    mariadb-libs-5.5.60-1.el7_5.x86_64
    [root@db1 ~]# yum remove mariadb-libs -y
    

    2.2 创建用户

    [root@db1 ~]# useradd mysql -s /sbin/nologin 
    [root@db1 ~]# id mysql
    uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
    

    2.3 创建相关目录

    #软件目录
    [root@db1 ~]# mkdir -p /software/database
    #软件目录
    [root@db1 ~]# mkdir -p /data/3306
    #日志目录
    [root@db1 ~]# mkdir -p /log/3306
    

    2.4 上传软件

    GlKt1I.png

    2.5 解压并创建软链接

    [root@db1 database]# tar -xvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz 
    #创建软链接
    [root@db1 database]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
    [root@db1 database]# ll
    总用量 707692
    lrwxrwxrwx. 1 root root        35 3月  31 23:01 mysql -> mysql-5.7.28-linux-glibc2.12-x86_64
    drwxr-xr-x. 9 root root      4096 3月  31 23:01 mysql-5.7.28-linux-glibc2.12-x86_64
    -rw-r--r--. 1 root root 724672294 3月  31 16:41 mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
    

    2.6 设置权限

    [root@db1 mysql]# chown -R mysql.mysql /software/ /data/ /log/
    

    2.7 设置环境变量

    #编辑/etc/profile文件
    [root@db1 ~]# vim /etc/profile  
    #添加一行
    export PATH=/software/database/mysql/bin:$PATH
    #生效配置                                                                             
    [root@db1 ~]# source /etc/profile
    #验证环境变量配置
    [root@db1 ~]# mysql -V           
    mysql  Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using  EditLine wrapper
    

    2.9 初始化系统库表

    初始化方式一:“mysqld --initialize-insecure”(推荐使用方式一初始化)

    初始化完成没有密码,密码后续自定义。

    [root@db1 ~]# mysqld --initialize-insecure --user=mysql --basedir=/software/database/mysql --datadir=/data/3306/
    #报错如下
    2020-03-31T15:22:30.402755Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-03-31T15:22:30.406574Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
    2020-03-31T15:22:30.406636Z 0 [ERROR] Aborting
    #解决如下:
    [root@db1 ~]# ls /data/3306/
    auto.cnf         client-key.pem  ib_logfile1         public_key.pem
    ca-key.pem       ib_buffer_pool  mysql               server-cert.pem
    ca.pem           ibdata1         performance_schema  server-key.pem
    client-cert.pem  ib_logfile0     private_key.pem     sys
    [root@db1 ~]# rm -rf /data/3306/*
    
    #重新初始化成功
    [root@db1 ~]# mysqld --initialize-insecure --user=mysql --basedir=/software/database/mysql --datadir=/data/3306/
    2020-03-31T15:31:20.109943Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-03-31T15:31:20.556875Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-03-31T15:31:20.624283Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-03-31T15:31:20.683017Z 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: abf0cb0d-7364-11ea-b642-000c29f292ec.
    2020-03-31T15:31:20.684363Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-03-31T15:31:21.412087Z 0 [Warning] CA certificate ca.pem is self signed.
    2020-03-31T15:31:22.404551Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    

    初始化方式二:“mysqld --initialize”

    区别在于mysqld --initialize初始化完成会生成一个临时密码,如下生成的临时密码为:#e5-,,MgLpdd,但必须在初次使用MySQL之前修改该密码

    [root@db1 ~]# mysqld --initialize --user=mysql --basedir=/software/database/mysql --datadir=/data/3306/
    2020-04-04T00:32:37.961724Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-04-04T00:32:39.249133Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-04-04T00:32:39.442169Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-04-04T00:32:39.520540Z 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: ca135a44-760b-11ea-96a0-000c2921d46c.
    2020-04-04T00:32:39.522674Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-04-04T00:32:40.163355Z 0 [Warning] CA certificate ca.pem is self signed.
    2020-04-04T00:32:40.301331Z 1 [Note] A temporary password is generated for root@localhost: #e5-,,MgLpdd
    

    2.9 定义my.cnf配置文件

    [root@db1 ~]# vim /etc/my.cnf 
    [mysqld]
    user=mysql
    basedir=/software/database/mysql
    datadir=/data/3306/
    server_id=6
    port=3306
    socket=/tmp/mysql.sock
    [mysql]
    socket=/tmp/mysql.sock
    

    2.10 准备MySQL启动脚本并启动MySQL服务

    [root@db1 ~]# cd /software/database/mysql/support-files/
    [root@db1 support-files]# ls
    magic  mysqld_multi.server  mysql-log-rotate  mysql.server
    #拷贝启动脚本到系统软件管理目录
    [root@db1 support-files]# cp mysql.server /etc/init.d/mysqld
    [root@db1 ~]# chkconfig --add mysqld
    [root@db1 ~]# systemctl start mysqld
    

    2.11 登录MySQL

    1. 使用mysqld --initialize初始化,需先修改密码才能登录。
    2. 使用mysqld --initialize-insecure初始化,无需修改密码,mysql直接可以登录。
    #无法登录mysql,需修改密码
    [root@db1 ~]# mysql
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    

    修改MySQL密码

    [root@db1 ~]# mysqladmin -uroot -p password mysql_admin@3306
    #注意:此处输入密码为初始化的临时密码,即:#e5-,,MgLpdd
    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.
    

    登录MySQL数据库

    [root@db1 ~]# mysql -p
    #此处输入密码为定义的MySQL密码
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.7.28 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> 
    

    相关文章

      网友评论

          本文标题:CentOS 7.6安装mysql-5.7.28

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