CentOS 7 下安装 MySQL 8.x

CentOS 7 下安装 MySQL 8.x作者:Grey
原文地址:
博客园:CentOS 7 下安装 MySQL 8.x
CSDN:CentOS 7 下安装 MySQL 8.x
环境CentOS 版本:CentOS 7
下载地址:CentOS 7
安装方法见:Linux 安装,快照,克隆
MySQL 版本:MySQL 8.0.30
下载地址见:MySQL 下载
新建用户组#> groupadd mysql创建 MySQL 用户并分配其用户组#> useradd -r -g mysql -s /bin/false mysql准备必要文件夹并赋予相应的权限#> mkdir -p /usr/local/mysql /data/mysql/#> chown -R mysql.mysql /usr/local/mysql/#> chown -R mysql.mysql /data/mysql/#> chmod -R 755 /data/mysql/#> chmod -R 755 /usr/local/mysql/注:其中/data/mysql是存放 MySQL 数据的目录 。
安装必要依赖【CentOS 7 下安装 MySQL 8.x】#> yum -y install wget gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel git bison#> yum install -y centos-release-scl-rh#> yum install -y centos-release-scl#> yum install -y devtoolset-10-gcc#> yum install -y devtoolset-10-gcc-c++如果安装比较慢,可以配置阿里云的镜像地址:CentOS 镜像
上传并解压 MySQL 安装包将下载好的 MySQL 安装包上传至服务器的/usr/local/目录下并解压,并将解压后的 mysql 安装目录中的内容放入/usr/local/mysql目录下
#> cd /usr/local/#> tar -xf mysql-8.0.30-linux-glibc2.17-x86_64-minimal.tar.xz#> mv mysql-8.0.30-linux-glibc2.17-x86_64-minimal/* mysql/初始化 MySQL 数据库#> /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql初始化完毕,会打印如下日志信息
2022-10-05T09:24:34.206466Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.2022-10-05T09:24:34.206531Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process 15332022-10-05T09:24:34.222068Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.2022-10-05T09:24:34.868013Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.2022-10-05T09:24:35.827528Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.修改 MySQL 配置参数MySQL 的配置文件默认位置是/etc/my.cnf,关于配置文件的说明见:option-files
修改配置之前,一个比较好的习惯的是先备份配置
#> cd /etc#> cp my.cnf my.cnf.backup/etc/my.cnf内容替换为如下内容:
[client]port=3306socket=/tmp/mysql.sockdefault-character-set=utf8#user=root#password=123[mysqld]server-id=1#skip-grant-tablesdefault_authentication_plugin=mysql_native_passwordport=3306user=mysqllog_bin=mysql-binbinlog_format=mixedmax_connections=200socket=/tmp/mysql.sockbasedir=/usr/local/mysqldatadir=/data/mysqlpid-file=/data/mysql/mysql.pidinit-connect='SET NAMES utf8'character-set-server=utf8default-storage-engine=INNODBlog_error=/data/mysql/mysql-error.logslow_query_log_file=/data/mysql/mysql-slow.log[mysqldump]quickmax_allowed_packet=16Mmy.cnf 文件的更多配置参数见:mysql-options
配置环境变量配置环境变量并应用环境变量
#> echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile#> source /etc/profile配置启动脚本【可选】#> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld给启动脚本赋予可执行权限
#> chmod +x /etc/init.d/mysqld这样就可以通过如下命令进行 MySQL 的启动了

经验总结扩展阅读