1、MySQL5.7.34 – 二进制安装
1.安装依赖包
yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
2.下载安装包 - - mysql-5.7.34
MySQL官网下载地址
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-el7-x86_64.tar.gz
tar -xvf mysql-5.7.34-el7-x86_64.tar.gz -C /usr/local/ && cd /usr/local/
mv mysql-5.7.34-el7-x86_64/ mysql
3.创建用户和组
useradd -r -M -s /sbin/nologin mysql
4.添加环境变量
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
vim /etc/man_db.conf
MANPATH_MAP /usr/local/sbin /usr/local/mysql/man
ln -s /usr/local/mysql/include/ /usr/include/mysql
- 写一个配置文件,告诉库文件lib在/usr/local/mysql下面
vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
ldconfig
6.创建数据存放目录
mkdir -p /data/mysql && chown -R mysql.mysql /data/mysql
- 初始化数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user mysql --datadir /data/mysql
8.修改配置文件
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
basedir=/usr/local/mysql
port=3306
symbolic-links=0
user=mysql
skip-name-resolve # 禁止域名解析,
[mysqld_safe]
log-error=/data/mysql/mysql.log # 此路径必须存在,不然会报错
pid-file=/data/mysql/mysql.pid
9.配置服务启动脚本
1.修改服务配置信息
vim /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/data/mysql
2.开启自启动服务
cp /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/mysqld.service
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
10.启动mysql服务
systemctl daemon-reload
systemctl enable --now mysqld
ln -s /data/mysql/mysql.sock /tmp/mysql.sock
初始密码为空,登录:
mysql -uroot -p