(1)解压安装包
tar -xzvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/mysql
(2)创建数据目录
[root@hecs-161929 3306]# mkdir -p /data/mysql/3306/data
[root@hecs-161929 3306]# mkdir -p /data/mysql/3306/binlog
[root@hecs-161929 3306]# mkdir -p /data/mysql/3306/undolog
(3)数据目录赋权
useradd mysql
[root@hecs-161929 3306]# chown mysql:mysql -R /data/mysql/
(4)编辑配置文件
vi /etc/my.cnf[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/3306/data
log_bin=/data/mysql/3306/binlog/mysql-bin
port=3306
server_id=80082088203306
socket=/tmp/mysql.sock
gtid-mode=on
enforce-gtid-consistency=true
log_slave_updates=1
relay_log_info_repository=TABLE
master_info_repository=TABLE
relay_log_recovery=on
slow_query_log=ON
long_query_time=0.1innodb_undo_directory=/data/mysql/3306/undolog
innodb_undo_tablespaces=4
innodb_undo_logs=128
innodb_max_undo_log_size=1G
innodb_purge_rseg_truncate_frequency=32
innodb_undo_log_truncate=1[client][mysql]
prompt=(\\u@\\h) [\\d]\\_
(5)配置环境变量
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
(6) 初始化
mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --initialize-insecure --datadir=/data/mysql/3306/data --user=mysql &
initialize --会设置初始化密码(可以在error-log找到)
initialize-insecure --(不会设置初始化密码,在运维自动化过程中,减少初始化解析难度)
如果出现报错
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory执行yum -y install libaio后再次初始化
(7)启动数据库
mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &