当前位置:Gxlcms > 数据库问题 > CentOS7.4下MySQL5.7.28二进制方式安装

CentOS7.4下MySQL5.7.28二进制方式安装

时间:2021-07-01 10:21:17 帮助过:6人阅读

Linux系统版本:CentOS7.4
MySQL版本:5.7.28
在Linux平台有RPM包、二进制包、源码包3中安装方式,这一篇文章主要是以RPM包为例来介绍如何在Linux平台下进行MySQL的安装。
下载地址:
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

技术图片
具体安装步骤如下:
(1)首先卸载mariadb,不然后面会和安装mysql需要的库冲突:

  1. <code>[root@localhost ~]# rpm -qa | grep mariadb
  2. mariadb-libs-5.5.56-2.el7.x86_64
  3. [root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64</code>

(2)用root用户登录系统,增加mysql用户和组,数据库安装在此用户下:

  1. <code>[root@localhost ~]# groupadd mysql
  2. [root@localhost ~]# useradd -r -g mysql -s /bin/false mysql</code>

(3)准备数据目录
以/app/data为例,建议使用逻辑卷
[root@localhost ~]# mkdir -p /app/data
[root@localhost ~]# chown mysql.mysql /app/data/
[root@localhost ~]# chmod 750 /app/data
(4)准备二进制文件:

  1. <code>[root@localhost ~]# tar xvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
  2. root@localhost ~]# cd /usr/local
  3. [root@localhost local]# ln -sv mysql-5.7.28-linux-glibc2.12-x86_64 mysql
  4. ‘mysql’ -> ‘mysql-5.7.28-linux-glibc2.12-x86_64’</code>

(5)初始化MySQL:

  1. <code>[root@localhost ~]# cd /usr/local/mysql
  2. [root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/app/data
  3. 2019-11-03T09:47:18.263716Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
  4. 2019-11-03T09:47:19.059462Z 0 [Warning] InnoDB: New log files created, LSN=45790
  5. 2019-11-03T09:47:19.140866Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  6. 2019-11-03T09:47:19.207569Z 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: ed1cd8ec-fe1e-11e9-8c9c-000c29f8617a.
  7. 2019-11-03T09:47:19.209181Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
  8. 2019-11-03T09:47:19.646366Z 0 [Warning] CA certificate ca.pem is self signed.
  9. 2019-11-03T09:47:20.056792Z 1 [Note] A temporary password is generated for root@localhost: rY-6f??#!<zO</code>

其中--basedir mysql基础目录 --datadir mysql数据存放目录,并创建了root用户的临时密码:rY-6f??#!<zO
(6)开启ssl连接:

  1. <code>[root@localhost mysql]# bin/mysql_ssl_rsa_setup
  2. 2019-11-03 23:09:55 [ERROR] Failed to access directory pointed by --datadir. Please make sure that directory exists and is accessible by mysql_ssl_rsa_setup. Supplied value : /usr/local/mysql/data
  3. [root@localhost mysql]# bin/mysql_ssl_rsa_setup --datadir=/app/data</code>

命令后面不加参数报错,加了--datadir后不报错
(7)编辑配置文件,保存退出:

  1. <code>[root@localhost mysql]# vim /etc/my.cnf
  2. [mysqld]
  3. # GENERAL
  4. datadir=/app/data
  5. socket=/app/data/mysql.sock
  6. user=mysql
  7. default-storage-engine=InnoDB
  8. [mysqld_safe]
  9. log-error=/app/data/mysql-error.log
  10. pid-file=/app/data/mysqld.pid
  11. [client]
  12. socket=/app/data/mysql.sock</code>

(8)启动MySQL:

  1. <code>[root@localhost mysql]# bin/mysqld_safe --user=mysql &</code>

(9)配置环境变量:
[root@localhost ~]# vim /etc/profile
#添加下面一行
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost ~]# source /etc/profile

(10)设置开机启动:

  1. <code>[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
  2. [root@localhost mysql]# chkconfig --add mysql.server</code>

(11)测试登录成功:

  1. <code>
  2. [root@localhost ~]# mysql -uroot -p
  3. Enter password:
  4. Welcome to the MySQL monitor. Commands end with ; or \g.
  5. Your MySQL connection id is 2
  6. Server version: 5.7.28
  7. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  12. mysql></code>

CentOS7.4下MySQL5.7.28二进制方式安装

标签:下载地址   def   dep   步骤   linux   kconfig   time   dir   mariadb   

人气教程排行