MySQL8.0 RPM方式部署

释放双眼,带上耳机,听听看~!

卸载老的数据库

[root@blogs /]# rpm -pa | grep mysql
[root@blogs /]# yum remove mysql-xxx-xxx-

[root@blogs /]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@blogs /]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps

使用mysql 官方给定yum源进行部署

[root@blogs src]# wget  https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
[root@blogs src]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm 
[root@blogs src]# yum clean all 
[root@blogs src]# yum makecache

查看mysql源内的mysql

以下两条命令都可以
[root@blogs src]# yum repolist all | grep mysql
[root@blogs src]# yum list | grep mysql-community

安装mysql8

当我们执行yum install mysql-community-server的时候,也就安装了mysql,默认mysql会安装以下四个包

mysql-community-server.x86_64   
mysql-community-client.x86_64    
mysql-community-common.x86_64         
mysql-community-libs.x86_64 
mysql-community-devel.x86_64    (默认不安装)

以下给出几种安装方法
1)直接使用yum安装
我们的机器一般都是x86的,即使不加后缀,yum会判断本机的系统机构进行部署

yum install mysql-community-server.x86_64  -y

2)指定安装包安装

yum install mysql-community-server.x86_64 mysql-community-client.x86_64 mysql-community-common.x86_64 mysql-community-libs.x86_64 mysql-community-devel.x86_64 -y

3) 通过rpm方式进行安装
我们总所周知,yum安装的就是rpm包,只是解决了依赖关系,把含有依赖的包全部进行部署,如果我们在内网内没有yum环境,那么这里则使用传统的rpm方式进行部署
rpm包下载地址:http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/
进去后找到相应架构的rpm包进行下载,我这里也有下载完成的,放到了百度网盘

安装包如下:

[root@blogs src]# du -sh mysql*
28K mysql80-community-release-el7-1.noarch.rpm
39M mysql-community-client-8.0.18-1.el7.x86_64.rpm
600K    mysql-community-common-8.0.18-1.el7.x86_64.rpm
6.6M    mysql-community-devel-8.0.18-1.el7.x86_64.rpm
3.7M    mysql-community-libs-8.0.18-1.el7.x86_64.rpm
430M    mysql-community-server-8.0.18-1.el7.x86_64.rpm

安装顺序如下:

[root@blogs src]# yum install libaio.x86_64 libaio-devel.x86_64 -y
rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm

设置my.cnf文件

一定要在启动mysql前进行配置my.cnf

[root@blogs /]# cat /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
server-id = 1
port = 3306
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/run/mysqld.pid
socket = /usr/local/mysql/run/mysql.sock
log_error = /usr/local/mysql/logs/mysql_error.log
default_authentication_plugin=mysql_native_password
tmpdir = /tmp
user = mysql
bind-address = 0.0.0.0
#skip-grant-tables
skip-external-locking
skip_name_resolve = 1
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
lower_case_table_names = 1
max_connections = 100
max_connect_errors = 200
max_allowed_packet = 128M
interactive_timeout = 1800
wait_timeout = 1800
tmp_table_size = 134217728
max_heap_table_size = 134217728
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/logs/mysql_slow_query.log
long_query_time = 5
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 5
min_examined_row_limit = 100

创建mysql配置目录及用户组

[root@blogs /]# mkdir /usr/local/mysql/{data,logs,run} -p 
[root@blogs /]# userdel -r mysql
[root@blogs /]# useradd -M -s /bin/false -U mysql
[root@blogs /]# chown -Rf mysql.mysql /usr/local/mysql/*
[root@blogs /]# chown -Rf mysql.mysql /var/log/mysqld.log
[root@blogs /]# chown -Rf mysql.mysql /var/lib/mysql-*

启动mysql

[root@blogs /]# systemctl start mysqld
[root@blogs /]# systemctl enable mysqld

查看初始密码

[root@blogs /]# cat /usr/local/mysql/logs/mysql_error.log | grep password 
2019-11-08T10:22:56.717596Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ya18b8tgWa#w

修改初始密码

[root@blogs /]# mysql -u root -p
Enter password: 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.02 sec)

数据库加固

[root@blogs /]# mysql_secure_installation

使用ssl来加密mysql连接

[root@blogs /]# mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

查看数据库用户加密方式

mysql> use mysql;

mysql> select Host,User,plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧