MySQL8.0已经正式发布了,提供了很多新特性,性能提升也是很明显。
可以直接使用国内的镜像源进行下载
wget -c mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-8.0.22-linux-glibc2.17-x86_64-minimal.tar.xz
centos7上glibc已经是2.17版本了,下载对应的版本即可。
需要安装系统依赖包
yum -y install libaio
解压安装
tar xvf mysql-8.0.22-linux-glibc2.17-x86_64-minimal.tar.xz
mv mysql-8.0.22-linux-glibc2.17-x86_64-minimal /usr/local/
cd /usr/local/
ln -s mysql-8.0.22-linux-glibc2.17-x86_64-minimal mysql
初始化的时候,需要指定运行用户,因此需要创建运行用户,并创建数据目录
useradd -M -s /sbin/nologin mysql
mkdir -p /data/mysql8/data
chown mysql.mysql /data/mysql8/data
初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/data/mysql8/data
初始化后,默认的 用户是root@localhost,没有密码
配置文件
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql8/data
socket=/data/mysql8/mysql.sock
[client]
socket=/data/mysql8/mysql.sock
设置启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
修改对应的程序和数据目录
sed -i 's#^basedir=$#basedir=/usr/local/mysql#g' /etc/init.d/mysqld
sed -i 's#^datadir=$#datadir=/data/mysql8/data#g' /etc/init.d/mysqld
/etc/init.d/mysqld start
/usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.22 MySQL Community Server - GPL
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>
安装很简单,测试可以直接用。如果是生产环境中使用,具体的参数配置,可以慢慢测试调整。