Installation MySQL-8.0.28 on CentOS 8.3
一、Installation MySQL-8.0.28 on CentOS 8.3
1 地址
2 下载图片
二、创建相关目录
1 创建软件目录
mkdir -p /opt/mysqlxyz/database
2 创建数据目录
mkdir -p /opt/mysqlxyz/data
3 创建日志目录
mkdir -p /opt/mysqlxyz/binlog
4 创建用户组
groupadd mysqlxyz
5 创建用户
useradd -g mysqlxyz mysqlxyz -s /sbin/nologin
### useradd mysqlxyz -r -M -s /sbin/nologin
id mysqlxyz
6 设置权限
chown -R mysqlxyz.mysqlxyz /opt/mysqlxyz/database /opt/mysqlxyz/data /opt/mysqlxyz/binlog
二、下载&解压
1 wget 下载
mkdir /opt/software && cd /opt/software
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.28-linux-glibc2.12-x86_64.tar
2 解压
mkdir -p /opt/software/mysql-8028
tar -xf /opt/software/mysql-8.0.28-linux-glibc2.12-x86_64.tar -C /opt/software/mysql-8028 && cd /opt/software/mysql-8028 && ll
xz -d /opt/software/mysql-8028/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz && ll
tar -xvf /opt/software/mysql-8028/mysql-8.0.28-linux-glibc2.12-x86_64.tar -C /opt/mysqlxyz/database && cd /opt/mysqlxyz/database && ll
包很大,得小等一会,可不要以为是卡了,就按Ctrl+C停止掉。 这里包很多末晕了~
修改目录名称
mv /opt/mysqlxyz/database/mysql-8.0.28-linux-glibc2.12-x86_64 /opt/mysqlxyz/database/mysql-8028
3 查看版本
4 设置权限
chown -R mysqlxyz.mysqlxyz /opt/mysqlxyz/database
三、设置环境变量
vi /etc/profile
export PATH=$PATH:/opt/mysqlxyz/database/mysql-8028/bin
source /etc/profile
四、安装 mysql-8.0.28
1 初始化系统库表(带有临时密码)
mysqld --initialize --user=mysqlxyz --basedir=/opt/mysql-8028/data/mysql-8.0.28 --datadir=/opt/mysqlxyz/data
2 初始化系统库表(密码为空)
[root@master01 ~]# mysqld --initialize-insecure --user=mysqlxyz --basedir=/opt/mysqlxyz/database/mysql-8028 --datadir=/opt/mysqlxyz/data
2022-11-05T07:49:55.452725Z 0 [System] [MY-013169] [Server] /opt/mysqlxyz/database/mysql-8028/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 10180
2022-11-05T07:49:55.491536Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-11-05T07:49:56.875007Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-11-05T07:50:01.393584Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
3 配置文件设置 /etc/my.cnf
cat > /etc/my.cnf <<EOF
[mysqld]
user=mysqlxyz
basedir=/opt/mysqlxyz/database/mysql-8028
datadir=/opt/mysqlxyz/data
port=3306
socket=/tmp/mysql-8028.sock
server_id=6
[mysql]
socket=/tmp/mysql-8028.sock
[client]
socket=/tmp/mysql-8028.sock
EOF
4 启动脚本
cd /opt/mysqlxyz/database/mysql-8028/support-files && ll
### 将服务文件拷贝到init.d下,并重命名为mysql8028
cp /opt/mysqlxyz/database/mysql-8028/support-files/mysql.server /etc/init.d/mysql8028
### 赋予可执行权限 可省略
chmod +x /etc/init.d/mysql8028
### 添加服务
chkconfig --add mysql8028
### 显示服务列表
chkconfig --list
### 启动 mysql8028
systemctl daemon-reload
systemctl start mysql8028
systemctl status mysql8028
### 登录
mysql -uroot -p
### 退出
exit;
5 使用 mysqladmin 修改密码
### 按两次回车即可
mysqladmin -uroot -p password xxx
### 登录
mysql -uroot -p
六、开放远程连接
1 localhost修改为%,使用远程连接
use mysql;
select user, host from user;
update user set host = '%' where user = 'root';
flush privileges;
2 允许远程连接 授权
### MySQL 8.0已经不支持下面这种命令写法
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'iyuyi.xyz@gamil.com' WITH GRANT OPTION;
### 正确的写法是先创建用户
CREATE USER 'xyz'@'%' IDENTIFIED BY 'iyuyixyz';
### 再给用户授权
grant all privileges on *.* to 'xyz'@'%' ;
### 默认就有root用户,可以直接授权
grant all privileges on *.* to 'root'@'%' WITH GRANT OPTION;
3 刷新一下权限,不刷新有可能也能生效
flush privileges;
七、防火墙
### 关闭防火墙
systemctl stop firewalld
### 开放3306端口命令
firewall-cmd --zone=public --add-port=3306/tcp --permanent
### 配置立即生效
firewall-cmd --reload
云主机需配置安全组
在入方向规则,允许3306放行
navicat连接
X、One Step Success
###
dnf install -y vim tar tree make net-tools libaio
mkdir -p /opt/mysqlxyz/database
mkdir -p /opt/mysqlxyz/data
mkdir -p /opt/mysqlxyz/binlog
groupadd mysqlxyz
useradd -g mysqlxyz mysqlxyz -s /sbin/nologin
chown -R mysqlxyz.mysqlxyz /opt/mysqlxyz/database /opt/mysqlxyz/data /opt/mysqlxyz/binlog
### 欧拉执行 22.09
chmod 777 /opt/mysqlxyz
chmod 777 /opt/mysqlxyz/data
chmod 777 /opt/mysqlxyz/database
chmod 777 /opt/mysqlxyz/binlog
sudo ln -s /usr/lib64/libtinfo.so.6.3 /usr/lib64/libtinfo.so.5
###
mkdir /opt/software && cd /opt/software
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.28-linux-glibc2.12-x86_64.tar
mkdir -p /opt/software/mysql-8028
tar -xf /opt/software/mysql-8.0.28-linux-glibc2.12-x86_64.tar -C /opt/software/mysql-8028 && cd /opt/software/mysql-8028 && ll
xz -d /opt/software/mysql-8028/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz && ll
tar -xvf /opt/software/mysql-8028/mysql-8.0.28-linux-glibc2.12-x86_64.tar -C /opt/mysqlxyz/database && cd /opt/mysqlxyz/database && ll
mv /opt/mysqlxyz/database/mysql-8.0.28-linux-glibc2.12-x86_64 /opt/mysqlxyz/database/mysql-8028 && ll
chown -R mysqlxyz.mysqlxyz /opt/mysqlxyz/database && ll
cp /opt/mysqlxyz/database/mysql-8028/bin/* /usr/local/bin
mysqld --initialize-insecure --user=mysqlxyz --basedir=/opt/mysqlxyz/database/mysql-8028 --datadir=/opt/mysqlxyz/data
###
cat > /etc/my.cnf <<EOF
[mysqld]
user=mysqlxyz
basedir=/opt/mysqlxyz/database/mysql-8028
datadir=/opt/mysqlxyz/data
port=3306
socket=/tmp/mysql-8028.sock
server_id=6
[mysql]
socket=/tmp/mysql-8028.sock
[client]
socket=/tmp/mysql-8028.sock
EOF
###
cp /opt/mysqlxyz/database/mysql-8028/support-files/mysql.server /etc/init.d/mysql8028
chmod +x /etc/init.d/mysql8028
chkconfig --add mysql8028
systemctl daemon-reload
systemctl start mysql8028
###
mysqladmin -uroot -p password root
mysql -uroot -proot
use mysql;
select user, host from user;
update user set host = '%' where user = 'root';
flush privileges;
grant all privileges on *.* to 'root'@'%' WITH GRANT OPTION;
flush privileges;
###
systemctl stop firewalld
Y、Error message
1 mysqld 报错
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决
yum install -y libaio
2 使用 Linux- Generic 包安装时,连接服务却报错了。
mysql -V
./mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
解决
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
### 欧拉执行,不是忽略
sudo ln -s /usr/lib64/libtinfo.so.6.3 /usr/lib64/libtinfo.so.5
3 登录navicat数报错Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts'
mysql> flush hosts;
Query OK, 0 rows affected, 1 warning (0.01 sec)
Z、Related Links
1、安装 MySQL-5.7.35
Installation MySQL-5.7.35 on CentOS 7.9:https://www.cnblogs.com/huaxiayuyi/p/16758720.html
2、集群部署 MySQL-8.0.28
MySQL-8.0.28 Cluster Deployment One-Master Multi-Slave:https://www.cnblogs.com/huaxiayuyi/p/16859506.html