CentOS7下离线安装mysql5.7

一、下载MySQL离线安装包

访问MySQL官网https://downloads.mysql.com/archives/community/页面。Product Version选择5.7.28,Operating System选择Red Hat Enterprise Linux,OS Version选择Red Hat Enterprise Linux7,下载MySQL的4个核心安装包,如下图:

二、系统安装前准备

1、拷贝安装包到centos7目录,如/usr/local/mysql下。

[root@localhost mysql]# ls
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm

2、查询并卸载系统自带的Mariadb。

[root@localhost mysql]#  rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@localhost mysql]#  rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
[root@localhost mysql]#  rpm -qa|grep mariadb

三、MySQL安装与配置

1、查询并安装libaio。

[root@localhost bak]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64

2、安装MySQL离线包。
依次安装mysql-community-common-5.7.28-1.el7.x86_64.rpm 、mysql-community-libs-5.7.28-1.el7.x86_64.rpm、mysql-community-client-5.7.28-1.el7.x86_64.rpm、mysql-community-server-5.7.28-1.el7.x86_64.rpm 这四个包。

[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
Warnung: mysql-community-common-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, Schlüssel-ID 5072e1f5: NOKEY
Vorbereiten...                                                          (100################################# [100%]
Aktualisierung/ Installation...

   1:mysql-community-common-5.7.28-1.e                                  (  2################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
Warnung: mysql-community-libs-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, Schlüssel-ID 5072e1f5: NOKEY
Vorbereiten...                                                          (100################################# [100%]
Aktualisierung/ Installation...

   1:mysql-community-libs-5.7.28-1.el7                                  (  1################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
Warnung: mysql-community-client-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, Schlüssel-ID 5072e1f5: NOKEY
Vorbereiten...                                                          (100################################# [100%]
Aktualisierung/ Installation...

   1:mysql-community-client-5.7.28-1.e                                  (  2################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
Warnung: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, Schlüssel-ID 5072e1f5: NOKEY
Vorbereiten...                                                          (100################################# [100%]
Aktualisierung/ Installation...

   1:mysql-community-server-5.7.28-1.e                                  (  1################################# [100%]

3、配置MySQL数据库。
编辑/etc/my.cnf文件,添加skip-grant-tables、character_set_server=utf8、init_connect='SET NAMES utf8'配置如下:

[root@localhost mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: loggin
g
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-grant-tables  #设置免密登录
character_set_server=utf8 #设置数据库默认字符集UTF-8
init_connect='SET NAMES utf8' #设置会话默认字符集UTF-8
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

4、启动mysql服务,登录并设置登录密码。

[root@localhost mysql]# systemctl start mysqld.service
[root@localhost mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
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> update mysql.user set authentication_string=password('*Pa55Word*') where user='root';
Query OK, 1 row affected, 1 warning (0,00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0,00 sec)

mysql> exit
Bye

5、停止MySQL服务,并关闭免密登录。
停止MySQL服务,编辑my.cnf 文件,将skip-grant-tables免密登录注销。

[root@localhost mysql]# systemctl stop  mysqld.service
[root@localhost mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: loggin
g
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#skip-grant-tables  #设置免密登录
character_set_server=utf8 #设置数据库默认字符集UTF-8
init_connect='SET NAMES utf8' #设置会话默认字符集UTF-8
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

6、重启MySQL服务,使用密码登录并开启远程访问权限。

[root@localhost mysql]# systemctl start mysqld.service
[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28

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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> alter user user() identified by "*Pa55Word*";
Query OK, 0 rows affected (0,00 sec)

mysql>  grant all privileges on *.* to 'root'@'%' identified by '*Pa55Word*' with grant option;
Query OK, 0 rows affected, 1 warning (0,00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0,00 sec)

mysql> exit
Bye

你可能感兴趣的:(CentOS7下离线安装mysql5.7)