CentOS7.5二进制安装MySQL-5.7.22

mysql-5.7.22二进制包下载地址 MD5值 9ef7a05695f8b4ea29f8d077c3b415e2

https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

mysql-5.7.23二进制包下载地址 MD5值 d903d3dbf235b74059a4b3e216c71161

https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

mysql-5.7.24二进制包下载地址 MD5值 9ef7a05695f8b4ea29f8d077c3b415e2

https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

⚠️⚠️⚠️

二进制安装mysql的启动脚本和 安装目录/mysql/bin/mysqld_safe 这两个文件中都是默认/usr/local/mysql,如果安装目录不在/usr/local/下,需要修改这两个文件中的路径,即把/usr/local替换为mysql安装目录

sed -i 's#/usr/local#/application#g' /etc/init.d/mysql /application/mysql/bin/mysqld_safe


1.下载MySQL-5.7.22二进制包

wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

2.解压缩mysql二进制包到/usr/local

tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local

3.修改名称、做软连接

mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.22 && 
ln -s /usr/local/mysql-5.7.22 /usr/local/mysql

4.创建mysql用户

useradd -M -s /bin/nologin mysql

5.编辑主配置文件,myql-5.7.22二进制包默认没有mysql配置文件

⚠️如果指定了mysql的socket文件位置,则必须添加[client]标签并同时指定socket文件位置,否则客户端会从/tmp下找socket文件

#备份/etc/my.cnf
mv /etc/my.cnf /etc/my.cnf.old

#以下配置为最精简版,可根据实际情况进行相应设置
cat >> /etc/my.cnf <<'EOF'
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
user=mysql
log-error=/usr/local/mysql/data/error.log

[client]
socket=/var/lib/mysql/mysql.sock
EOF

6.创建socket文件目录

mkdir -p /var/lib/mysql

7.相关目录、文件授权

chown -R mysql.mysql /usr/local/mysql* /var/lib/mysql
chown mysql.mysql /etc/my.cnf

8.拷贝启动脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

9.初始化mysql

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

--user                         #指定mysql用户
--basedir                     #指定mysql安装目录
--datadir                    #指定mysql数据目录
--initialize-insecure        #不生成随机密码

⚠️⚠️⚠️mysql-5.7.22初始化没有提示!!!

10.添加mysql命令环境变量

#导出mysql命令环境变量
echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh

#使配置生效
source /etc/profile

11.配置systemd管理mysql

cat >> /etc/systemd/system/mysqld.service <<'EOF'
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF

12.启动mysql、检查启动

#重新加载systemd系统服务
systemctl daemon-reload

#启动mysql并加入开机自启
systemctl start mysqld && systemctl enable mysqld

#查看mysql端口
$ netstat -ntpl  | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      31349/mysqld

13.进入mysql并设置密码

#进入mysql
mysql

#设置mysql密码
mysql> set password='123';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

到此,mysql5.7.22二进制安装完成!!!

泡泡吐肥皂o © gitbook.pptfz.top 2021 all right reserved,powered by Gitbook文件修订时间: 秃笔南波湾!!!

results matching ""

    No results matching ""