MySQL5.7二进制安装,有手就行

环境准备

  • OS:Centos7
  • IP:192.168.10.0/24,
  • hostname:mysql-1
  • 关闭防火墙,selinux

清理历史环境

[root@mysql-1 ~]# rpm -aq | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@mysql-1 ~]# yum remove mariadb-libs -y

创建管理MySQL的用户

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

创建相关目录

创建软件目录

[root@mysql-1 ~]# mkdir -p /app/database

创建数据目录

[root@mysql-1 ~]# mkdir -p /data/3306

创建日志目录

[root@mysql-1 ~]# mkdir -p /binlog/3306

设置权限

[root@mysql-1 log]# chown mysql.mysql -R /app/database/ /data/3306/ /binlog/3306/	

上传软件

MySQL5.7官网下载地址

上传MySQL 5.7二进制包到/app/database/

[root@mysql-1 database]# tar xvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz 
[root@mysql-1 database]# mv mysql-5.7.28-linux-glibc2.12-x86_64/ mysql-5.7.28

设置环境变量

[root@mysql-1 ~]# vim /etc/profile

添加如下内容

export PATH=/app/database/mysql-5.7.28/bin:$PATH

生效配置

[root@mysql-1 ~]# source /etc/profile
[root@mysql-1 ~]# mysql -V
mysql  Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using  EditLine wrapper

初始化系统表

[root@mysql-1 data]# mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql-5.7.28 --datadir=/data/3306

显示一下内容表示初始化成功

2020-03-31T05:10:13.149093Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-31T05:10:13.252907Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-31T05:10:13.273152Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-31T05:10:13.328798Z 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: e6ddd3b8-730d-11ea-b7ea-000c2985b0a2.
2020-03-31T05:10:13.329424Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2020-03-31T05:10:13.753966Z 0 [Warning] CA certificate ca.pem is self signed.
2020-03-31T05:10:14.041334Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

初始化方式

  • MySQL5.7
    • mysql --initialize:初始化完成之后会有一个12位的临时密码,但是必须在使用mysql之前重置这个密码,否则没法使用。密码管理使用严格模式:3种密码复杂度
    • mysql --initialize-insecure:初始化完成后无密码,可后期随时修改。无密码复杂度要求
  • MySQL5.6
    • mysql_install_db

修改配置文件

cat > /etc/my.cnf << EOF
[mysqld] 
user=mysql
basedir=/app/database/mysql-5.7.28
datadir=/data/3306
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
EOF

启动MySQL

准备启动脚本

[root@mysql-1 support-files]# cd /app/database/mysql-5.7.28/support-files/
# 拷贝MySql启动脚本至系统软件管理目录中
[root@mysql-1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@mysql-1 ~]# service mysqld start/stop/restart
[root@mysql-1 ~]# chkconfig --add mysqld

启动MySQL

[root@mysql-1 ~]# systemctl start mysqld
# 设置开机自启
[root@mysql-1 ~]# systemctl enable mysqld

MySQL5.7二进制安装,有手就行

上一篇:二进制的加法


下一篇:MySQL 之自带工具使用介绍