CentOS7.9绿色安装mysql5.7.44
1、下载 MySQL 5.7.44 二进制包
cd /opt
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
2、安装依赖库
yum install -y libaio numactl-libs
3、解压并配置 MySQL
(1)解压到目标目录
tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.44-linux-glibc2.12-x86_64 mysql-5.7.44
创建软链接便于管理:
ln -s mysql-5.7.44 mysql
(2)创建 MySQL 用户(安全考虑)
useradd -r -s /sbin/nologin mysql
(3)创建数据目录并授权
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
chmod 750 /data/mysql
3、初始化数据库
cd mysql
bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/data/mysql
root密码:KW+kNedDE5hd
使用安全的 SSL 初始化:
bin/mysql_ssl_rsa_setup --basedir=/opt/mysql --datadir=/data/mysql
4、配置mysql
(1)创建配置文件 my.cnf
vi /etc/my.cnf
内容如下:
[mysqld]
basedir=/opt/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
(2)配置 mysql.server 脚本
cp support-files/mysql.server /etc/init.d/mysqld
编辑脚本,设置路径:
vi /etc/init.d/mysqld
修改以下两行:
5、设置开机启动
chkconfig --add mysqld
chkconfig mysqld on
6、启动 MySQL
service mysqld start
检查状态:
service mysqld status
ps -ef | grep mysql
7、设置环境变量
echo 'export PATH=/opt/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
8、登录并修改密码
使用初始化生成的临时密码登录:
mysql -u root -p
进入后立即修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxx';
FLUSH PRIVILEGES;
9、验证安装
mysql -u root -p -e "SELECT VERSION();"