一、环境信息
centos7.6_x86、glib2.17
mysql官网下载地址:MySQL :: Download MySQL Community Server
二、 二进制安装
#下载解压安装包
[root@hadoop03 ~]# wget -c https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.39-linux-glibc2.17-x86_64.tar.xz
[root@hadoop03 ~]# xz -d mysql-8.0.39-linux-glibc2.17-x86_64.tar.xz
[root@hadoop03 ~]# tar -xvf mysql-8.0.39-linux-glibc2.17-x86_64.tar
[root@hadoop03 ~]# mv mysql-8.0.39-linux-glibc2.17-x86_64 mysql
[root@hadoop03 ~]# mv mysql /usr/local/
#创建数据存放目录以及日志目录、mysql.sock文件存放目录
[root@hadoop03 mysql]# mkdir /data/mysql/{data,logs,run} -p
#以普通用户启动mysql,所以需要更改目录权限
[root@hadoop03 mysql]# chown admin:admin -R /usr/local/mysql/
[root@hadoop03 mysql]# chown admin:admin -R /data/
#编写配置文件my.cnf
[root@hadoop03 mysql]# su admin
[admin@hadoop03 mysql]$ vi my.cnf
[mysqld_safe]
pid-file=/data/mysql/logs/mysqld.pid
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/data
socket=/data/mysql/run/mysql.sock
log_error=/data/mysql/logs/alert.log
pid_file=/data/mysql/logs/mysqld.pid
#初始化mysql
[admin@hadoop03 mysql]$ ./bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize-insecure
#启动mysql
[admin@hadoop03 mysql]$ ./bin/mysqld_safe --defaults-file=my.cnf &
#进入mysql,也可以./bin/mysql -S /data/mysql/run/mysql.sock命令进入
[admin@hadoop03 mysql]$ ./bin/mysql -uroot -h127.0.0.1
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.39 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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>
三、 yum方式安装
官网下载地址:MySQL :: Download MySQL Yum Repository
[root@hadoop03 ~]# rpm -ivh mysql84-community-release-el7-1.noarch.rpm
#安装依赖
[root@hadoop03 yum.repos.d]# yum install perl net-tools -y
[root@hadoop03 ~]# yum install mysql-server mysql mysql-common mysql-libs -y
#启动
[root@hadoop03 ~]# systemctl start mysqld
#查看mysql初始化密码
#登陆mysql,有个(需要\转义一下
[root@hadoop03 ~]# mysql -uroot -pT2OpEi_Bw\(=p
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.4.2
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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>
四、docker方式安装
官网:https://download.docker.com/linux/static/stable/x86_64/
百度下载链接:链https://pan.baidu.com/s/1WyqqRmGKjKcTwjEZEn4PUQ?pwd=q8xp 提取码: q8xp
[root@hadoop03 ~]# tar -xzvf docker-19.03.15.tgz
[root@hadoop03 ~]# cp docker/* /usr/bin/
[root@hadoop03 ~]# vi /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target docker.socket
[Service]
Type=notify
EnvironmentFile=-/run/flannel/docker
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock --selinux-enabled=false --log-opt max-size=1g --default-ulimit nofile=65535:65535
ExecReload=/bin/kill -s HUP
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@hadoop03 ~]# systemctl daemon-reload
[root@hadoop03 ~]# systemctl start docker
#拉取镜像
[root@hadoop03 ~]# docker pull swr.cn-north-1.myhuaweicloud.com/iivey/mysql:8.0.23
#启动
[root@hadoop03 ~]# mkdir /dockerdata/mysql/db -p
[root@hadoop03 ~]# setenforce 0
[root@hadoop03 ~]# sed -i 's/^SELINUX=enforcing/SELINUX=Permissive/' /etc/sysconfig/selinux
[root@hadoop03 ~]# docker run -itd -p 3306:3306 --name mysql8 --restart unless-stopped -v /etc/localtime:/etc/localtime -v /dockerdata/mysql/db:/var/lib/mysql -e MYSQL_DATABASE="iivey" -e MYSQL_USER="iivey" -e MYSQL_PASSWORD="mysql123" -e MYSQL_ROOT_PASSWORD="root123" swr.cn-north-1.myhuaweicloud.com/iivey/mysql:8.0.23 --default-authentication-plugin=mysql_native_password --character-set-server=utf8 --collation-server=utf8_bin
#登陆mysql
[root@hadoop03 ~]# mysql -uroot -proot123 -h127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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>