MySQL 5.7二进制安装

Posted 江洋大运

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 5.7二进制安装相关的知识,希望对你有一定的参考价值。

1.下载并上传软件至/server/tools,并解压软件

[root@web01 ~]# mkdir -p /server/tools  [root@web01 ~]# cd /server/tools/[root@web01 tools]# rz -Erz waiting to receive.[root@web01 tools]# lltotal 629756-rw-r--r-- 1 root root 644869837 May 8 2020 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz[root@web01 tools]# tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz [root@web01 tools]# lltotal 629756drwxr-xr-x 9 root root 129 Jan 27 20:13 mysql-5.7.26-linux-glibc2.12-x86_64-rw-r--r-- 1 root root 644869837 May  8  2020 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz[root@web01 tools]# mkdir /application[root@web01 tools]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql

2.用户的创建处理原始环境

[root@web01 ~]# rpm -qa | grep mariadbmariadb-libs-5.5.56-2.el7.x86_64[root@web01 ~]# yum remove -y mariadb-libs-5.5.56-2.el7.x86_64[root@web01 ~]# useradd -s /sbin/nologin mysql

3.设置环境变量

[root@web01 ~]# vim /etc/profileexport PATH=/application/mysql/bin:$PATH[root@web01 ~]# source /etc/profile[root@web01 ~]# mysql -Vmysql  Ver 14.14 Distrib 5.7.26for linux-glibc2.12 (x86_64) using  EditLine wrapper

4.授权目录为 mysql 用户

[root@web01 ~]# chown -R mysql.mysql /application/*[root@web01 ~]# chown -R mysql.mysql /data/[root@web01 ~]# ll /application/total 0drwxr-xr-x 9 mysql mysql 129 Jan 27 20:13 mysql[root@web01 ~]# ll -d /data/drwxr-xr-x 5 mysql mysql 42 Jan 27 20:09 /data/

5.初始化数据(创建系统数据)

  • 5.6 版本 初始化命令

    /application/mysql/scripts/mysql_install_db
  • 5.7 版本初始化命令 

    mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

说明:--initialize 参数:

1. 对于密码复杂度进行定制:12 位,4 种

2. 密码过期时间:180

3. 给 root@localhost 用户设置临时密码

报错: mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 

解决:[root@db01 ~]# yum install -y libaio-devel

--initialize-insecure 参数: 无限制,无临时密码 

[root@web01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data2021-01-27T12:34:53.296796Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2021-01-27T12:34:53.713332Z 0 [Warning] InnoDB: New log files created, LSN=457902021-01-27T12:34:53.762368Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2021-01-27T12:34:53.819561Z 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: 0e6e21e9-609c-11eb-9998-000c29289384.2021-01-27T12:34:53.820405Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2021-01-27T12:34:53.821186Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

6.配置文件的准备

[root@web01 ~]# cat >/etc/my.cnf<<EOF[mysqld]user=mysqlbasedir=/application/mysqldatadir=/data/mysql/datasocket=/tmp/mysql.sockserver_id=6port=3306[mysql]socket=/tmp/mysql.sockEOF

7.拷贝运行文件 启动数据库

  • service 启动

[root@web01 ~]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld[root@web01 ~]# /etc/init.d/mysqld startStarting MySQL. SUCCESS![root@web01 ~]# netstat -tunlpActive 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 1302/sshd tcp6 0 0 :::3306 :::* LISTEN 3043/mysqld tcp6 0 0 :::22 :::* LISTEN 1302/sshd
  • systemd 启动

[root@web01 ~]# cat >/etc/systemd/system/mysqld.service <<EOF[Unit]Description=MySQL ServerDocumentation=man:mysqld(8)Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnfLimitNOFILE = 5000EOF[root@web01 ~]# systemctl restart mysqld

以上是关于MySQL 5.7二进制安装的主要内容,如果未能解决你的问题,请参考以下文章

Liunx 下MYSQL 5.7 二进制安装

MySQL 5.7二进制安装

mysql 5.7 二进制普通安装

MySQLLinux下MySQL 5.55.6和5.7的RPM二进制和源码安装

(综合知识)RPM和二进制安装Mysql(含指定5.7安装)

mysql 5.7安装脚本