基于CentOS-7.7下MySQL-5.7离线安装

 

 

操作系统:Linux CentOS 7.7.1908

配置:8核8G

网络:内网

    1. 软件

MySQL安装包:mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar.tar

 

  • MySql离线安装

 

MySql的安装,可以在线或离线安装,由于内网机器通常不能连接互联网,这里重点介绍离线安装部署。

  1. 官网下载指定版本。

这里版本选5.7.28,OS选RHEL 64-bit,安装包选RPM Bundle(完整包)。官网地址: https://dev.mysql.com/downloads/mysql/

 

  1. 上传到服务器指定目录,并解压

# mkdir -p /usr/local/mysql-rpm

# cd /usr/local/mysql-rpm

# tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar.tar

  1. 卸载mariadb

# rpm -qa|grep mariadb

mariadb-libs-5.5.44-2.el7.centos.x86_64

# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

  1. 卸载MySql(如果有安装过,无则跳过)
  1. 移除MySql服务

# yum remove mysql mysql-server mysql-libs mysql-server

  1. 查看是否安装mysql等组件

# rpm -qa | grep -i mysql

mysql-community-client-5.7.28-1.el7.x86_64

mysql-community-libs-5.7.28-1.el7.x86_64

mysql-community-common-5.7.28-1.el7.x86_64

mysql-community-server-5.7.28-1.el7.x86_64

  1. 全部卸载

# rpm -e mysql-community-client-5.7.28-1.el7.x86_64

# rpm -e mysql-community-libs-5.7.28-1.el7.x86_64

# rpm -e mysql-community-common-5.7.28-1.el7.x86_64

# rpm -e mysql-community-server-5.7.28-1.el7.x86_64

  1. 查找mysql相关目录和文件,使用whereis或find命令

# whereis mysql

# find / -name mysql && find / -name my.cnf

/var/lib/mysql

/usr/bin/mysql

/usr/share/mysql

/etc/my.cnf

  1. 全部删除

# rm -rf /var/lib/mysql

# rm -rf /usr/bin/mysql

# rm -rf /usr/share/mysql

# rm -rf /etc/my.cnf

  1. 顺序安装MySql包

必须安装包:

# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm

# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm

# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm

# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm

非必须安装包,可选:

# rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm

# rpm -ivh mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm

# rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm

# rpm -ivh mysql-community-test-5.7.28-1.el7.x86_64.rpm

  1. 修改MySql配置

# vim /etc/my.cnf

在[mysqld]下面添加或修改如下参数

[mysqld]

datadir=/data/mysql

log-error=/data/mysql/log/mysqld.log

  1. 初始化数据库

# mysqld --initialize

  1. 创建目录并授权

# mkdir -p /data/mysql/log

# chown mysql:mysql /data/mysql -R

  1. 启动MySql数据库服务

# systemctl start mysqld.service

  1. 查看并设置开机启动

# systemctl list-unit-files | grep mysqld

mysqld.service                                disabled

mysqld@.service                               disabled

# systemctl enable mysqld

  1. 查看MySql运行状态

# systemctl status mysqld            

● mysqld.service - MySQL Server

   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

   Active: active (running) since Tue 2020-01-07 15:58:56 CST; 9s ago

     Docs: man:mysqld(8)

           http://dev.mysql.com/doc/refman/en/using-systemd.html

  Process: 202027 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)

  Process: 202002 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

Main PID: 202030 (mysqld)

    Tasks: 27

   CGroup: /system.slice/mysqld.service

           └─202030 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

 

 

Jan 07 15:58:55 bmsoft systemd[1]: Starting MySQL Server...

Jan 07 15:58:56 bmsoft systemd[1]: Started MySQL Server.

至此,MySql数据库安装成功!

  • MySql在线安装
  1. 下载MySsql官方的 Yum Repository

# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

  1. Repository安装

# yum -y install mysql57-community-release-el7-10.noarch.rpm

  1. 安装MySql服务器

# yum -y install mysql-community-server

  1. 启动MySql数据库服务

# systemctl start mysqld

  • MySql配置
  1. 设置MySql数据库密码
  1. 查看MySql初始密码

# grep 'temporary password' /data/mysql/log/mysqld.log

2020-01-06T08:07:11.180530Z 1 [Note] A temporary password is generated for root@localhost: tHwuL&ago7S8

  1. 使用初始密码登录

# mysql -uroot -ptHwuL&ago7S8

  1. 设置密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password';

  1. 开启MySql远程访问
  1. 设置所有IP都能访问

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;

  1. 刷新权限

mysql> flush privileges;

  1. firewalld添加MySql端口3306,然后重新载入

# firewall-cmd --zone=public --add-port=3306/tcp --permanent

# firewall-cmd --reload

  1. 字符集设置,建议设置为UTF-8

# vim /etc/my.cnf

分别在[client],[mysqld]下面添加或修改如下参数

[client]

default-character-set=utf8

 

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci

设置后,重启MySql,查看设置结果:

mysql> status;

--------------

mysql  Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using  EditLine wrapper

 

 

Connection id:          11

Current database:

Current user:           root@localhost

SSL:                    Not in use

Current pager:          stdout

Using outfile:          ''

Using delimiter:        ;

Server version:         5.7.28 MySQL Community Server (GPL)

Protocol version:       10

Connection:             Localhost via UNIX socket

Server characterset:    utf8

Db     characterset:    utf8

Client characterset:    utf8

Conn.  characterset:    utf8

UNIX socket:            /var/lib/mysql/mysql.sock

Uptime:                 50 min 57 sec

 

 

Threads: 6  Questions: 77  Slow queries: 0  Opens: 120  Flush tables: 1  Open tables: 113  Queries per second avg: 0.025

--------------

 

mysql> show variables like 'character_set%';

+--------------------------+----------------------------+

| Variable_name            | Value                      |

+--------------------------+----------------------------+

| character_set_client     | utf8                       |

| character_set_connection | utf8                       |

| character_set_database   | utf8                       |

| character_set_filesystem | binary                     |

| character_set_results    | utf8                       |

| character_set_server     | utf8                       |

| character_set_system     | utf8                       |

| character_sets_dir       | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

8 rows in set (0.01 sec)

 

  • MySql常用命令

启动MySql

# systemctl start mysqld

停止MySql

# systemctl stop mysqld

重启MySql

# systemctl restart mysqld

查看状态

# systemctl status mysqld

 

  • MySql目录说明

 

配置文件:/etc/my.cnf

日志文件:/data/mysql/log/mysqld.log

数据库文件目录:/data/mysql/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值