Noname
Noname

MySQL5.7.29安装-Centos7 RPM安装

安装环境

操作系统:Centos7 最小化安装

官网下载包

说明

需要下载的安装包版本信息如下:

mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar

特别说明:安装包中的el7表示的是Centos7的操作下的安装包,如果是其他的版本请下载el8或者是el6的版本
CentOS的el5, el6, el7代表什么
EL是Red Hat E nterprise L inux(EL)的缩写。
EL6是Red Hat 6.x,CentOS 6.x和CloudLinux 6.x的下载。
EL5是Red Hat 5.x,CentOS 5.x和CloudLinux 5.x的下载。
EL7是Red Hat 7.x,CentOS 7.x和CloudLinux 7.x的下载。

https://blog.cpmsxe.net/wp-content/uploads/2020/04/a6bc97277a5fff662bbe27b23cfc43d6.png

安装先决条件:

更新系统和安装wget下载软件使用

yum -y update
yum -y install wget

目的是移除mariadb软件

[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
[root@localhost ~]# rpm -qa|grep mariadb
[root@localhost ~]#

开放数据库的3306端口号

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

关闭SELinux【需要重启电脑】

sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
grep '^SELINUX=' /etc/selinux/config
reboot
getenforce

下载安装包:

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar

如果wget下载慢,请使用迅雷下载,再使用scp命令上传到服务器上

scp ./mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar -p 22 [email protected]:/root/

开始安装

解压并使用yum安装【如果使用rpm命令安装将有依赖的软件,因为此环境是最小化安装的Cento7】
mysql-community-common-5.7.29-1.el7.x86_64.rpm
mysql-community-libs-5.7.29-1.el7.x86_64.rpm
mysql-community-devel-5.7.29-1.el7.x86_64.rpm
mysql-community-client-5.7.29-1.el7.x86_64.rpm
mysql-community-server-5.7.29-1.el7.x86_64.rpm

tar xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
yum install mysql-community-common-5.7.29-1.el7.x86_64.rpm mysql-community-libs-5.7.29-1.el7.x86_64.rpm mysql-community-devel-5.7.29-1.el7.x86_64.rpm mysql-community-client-5.7.29-1.el7.x86_64.rpm mysql-community-server-5.7.29-1.el7.x86_64.rpm
reboot

数据库基本操作

获取mysql的 root用户的初始化密码

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2020-04-02T14:00:01.532776Z 1 [Note] A temporary password is generated for root@localhost: Ri=dB?fyw1N/

修改mysql的 root用户的初始化密码

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, 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 > alter user 'root'@'localhost' identified by 'blog.cpmsxe.net2020*PWD';
Query OK, 0 rows affected (0.00 sec)
mysql > flush privileges;
Query OK, 0 rows affected (0.00 sec)

允许以root身份远程登录mysql

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'blog.cpmsxe.net2020*PWD' 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的字符集为utf8

mysql> show variables like 'chara%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.03 sec)
mysql> exit
Bye

修改字符集:在/etc/my.cnf后面加入如下内容

[root@localhost ]# cat >>/etc/my.cnf <<EOF
> character-set-server=utf8
> collation-server=utf8_general_ci
>
> [client]
> default-character-set=utf8
> EOF
[root@localhost ~]# cat /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: logging
# 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
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
character-set-server=utf8
collation-server=utf8_general_ci

[client]
default-character-set=utf8

重启MySQL的服务

[root@localhost ~]# systemctl restart mysqld

发表回复

textsms
account_circle
email

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

Noname

MySQL5.7.29安装-Centos7 RPM安装
安装环境 操作系统:Centos7 最小化安装 官网下载包 说明 需要下载的安装包版本信息如下: mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 特别说明:安装包中的el7表示的是Centos7的…
扫描二维码继续阅读
2020-04-03