二进制部署Mysql8.0.31

二进制部署Mysql8.0.31

一、软件包下载

企业版:Enterprise  , 互联网行业一般不选择.

社区版本:选择
            源码包 编译安装:  source code    .tar.gz   
            通用二进制 

公司用什么版本数据库? 具体什么小版本号?
5.6.20 5.6.34 5.6.36  5.6.38  5.6.40    
5.7.18  5.7.20  5.7.22 5.7.31
8.0.23 8.0.31

通用二进制版本: 本文档采用此方式安装

https://downloads.mysql.com/archives/community/

选择版本,再选择Operating System: Linux - Generic

img

二、卸载MariaDB

在CentOS中默认安装有MariaDB,是MySQL的一个分支,主要由开源社区维护。CentOS 7及以上版本已经不再使用MySQL数据库,而是使用MariaDB数据库。如果直接安装MySQL,会和MariaDB的文件冲突。因此,需要先卸载自带的MariaDB,再安装MySQL。

#查看是否存在MariaDB
rpm -qa|grep mariadb

#卸载mariadb
yum remove mariadb*

三、MySQL二进制安装

3.1 创建mysql工作目录:

root@db01 ~]# mkdir -p /home/application/mysql

3.2、上传软件,并解压并改名为app

[root@db01 app]# tar -xf /root/mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz

[root@db01 app]# mv mysql-8.0.31-linux-glibc2.12-x86_64 /home/application/mysql/app

[root@db01 app]# ls -l /home/application/mysql/app
total 36
drwxr-xr-x  2 root root   4096 Mar  4 14:55 bin
-rw-r--r--  1 7161 31415 17987 Sep 13  2017 COPYING
drwxr-xr-x  2 root root     55 Mar  4 14:55 docs
drwxr-xr-x  3 root root   4096 Mar  4 14:55 include
drwxr-xr-x  5 root root    229 Mar  4 14:55 lib
drwxr-xr-x  4 root root     30 Mar  4 14:55 man
-rw-r--r--  1 7161 31415  2478 Sep 13  2017 README
drwxr-xr-x 28 root root   4096 Mar  4 14:55 share
drwxr-xr-x  2 root root     90 Mar  4 14:55 support-files

3.3、修改环境变量

[root@db01 app]# vim /etc/profile  
#加入一行
export PATH=$PATH:/home/application/mysql/app/bin

[root@db01 app]# source /etc/profile

3.4、建立mysql用户和组(如果有可忽略)

useradd -s /sbin/nologin mysql -M

3.5、创建mysql 数据目录,日志目录;并修改权限

mkdir -p /home/application/mysql/data
mkdir -p /home/application/mysql/data/logs

chown -Rf mysql.mysql /home/application/mysql/app
chown -Rf mysql.mysql /home/application/mysql/data
chown -Rf mysql.mysql /home/application/mysql/data/logs

3.6、初始化数据

[root@db01 ~]# mysqld --initialize-insecure  --user=mysql --basedir=/home/application/mysql/app --datadir=/home/application/mysql/data

2022-12-05T05:42:38.231032Z 0 [System] [MY-013169] [Server] /home/application/mysql/app/bin/mysqld (mysqld 8.0.31) initializing of server in progress as process 1796
2022-12-05T05:42:38.242323Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-12-05T05:42:43.737861Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-12-05T05:42:45.690512Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

四、配置mysql配置文件

[mysqld]
user=mysql
basedir=/home/application/mysql/app
datadir=/home/application/mysql/data
character_set_server=utf8
collation-server=utf8mb4_bin

#只能用IP地址检查客户端的登录,不用主机名,跳过域名解析
skip-name-resolve=1

#日志时间
log_timestamps=SYSTEM

#慢日志
long_query_time=3
slow_query_log=ON
slow_query_log_file=/home/application/mysql/data/logs/slow_query.log

#通用日志
general_log=1
general_log_file=/home/application/mysql/data/logs/mysql_general.log

#错误日志
log-error=/home/application/mysql/data/logs/mysql-error.log

# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

# 默认使用"mysql_native_password"插件认证
default_authentication_plugin=mysql_native_password

port=3306
socket=/tmp/mysql.sock
max_connections=1000
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_allowed_packet=300M

[mysql]
socket=/tmp/mysql.sock

五、使用systemd管理mysql

vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/home/application/mysql/app/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#reload从新加载下systemd
[root@db01 mysql]#  systemctl daemon-reload
#systemd 管理相关命令
systemctl  start  mysqld

六、创建root用户密码,并简单管理

[root@db01 ~]# mysqladmin -uroot -p  #无密码,直接回车

#创建root用户密码
mysql> alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'XXXX';
Query OK, 0 rows affected (0.01 sec)

#创建数据库
mysql> CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
Query OK, 1 row affected (0.00 sec)

#创建用户
mysql> CREATE USER 'zabbix'@'%' IDENTIFIED BY 'zabbix';
Query OK, 0 rows affected (0.01 sec)

#授权用户
mysql> GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%';
Query OK, 0 rows affected (0.01 sec)

#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容