主页 > InnoDB存储引擎 > MySQL 5.7安装(二进制安装包)

MySQL 5.7安装(二进制安装包)

小牛教程 InnoDB存储引擎 2021年10月30日

一、准备环境

1、检查当前环境是否安装MySQL,如果有则删除卸载

rpm -qa | grep mysql
pm -qa |grep mariadb
yum remove mariadb-libs-5.5.64-1.el7.x86_64

2、检查my.cnf文件,如果有则删除

rm /etc/my.cnf
rm /etc/mysql/my.cnf

二、下载安装MySQL

1、从官网下载MySQL5.7.34

1. 官网地址:https://downloads.mysql.com/archives/community
2. MySQL5.7.34 安装包下载地址:
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

2、安装MySQL 5.7.34

1.创建mysql用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql

2.解压安装包
cd /usr/local
tar zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local
ln -s mysql-5.7.34-linux-glibc2.12-x86_64 mysql
cd mysql

3.创建run、logs路径
mkdir run && chown mysql.mysql run
mkdir logs && chown mysql.mysql logs

4.初始化mysql
bin/mysqld --initialize --user=mysql
[Note] A temporary password is generated for root@localhost: :qq:&XSwq6HL

5. 修改my.cnf配置文件
[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
character-set-server = utf8mb4

6.初次启动mysql,记录此命令返回的随机密码
bin/mysqld_safe --user=mysql &

7.创建启动脚本
cp support-files/mysql.server /etc/init.d/mysql.server
/etc/init.d/mysqld status  
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
/etc/init.d/mysqld restart

8.设置mysql环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile

3、修改MySQL密码,创建用户

mysql -u root -p':qq:&XSwq6HL'
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'root-password';
CREATE USER 'root'@'::1' IDENTIFIED BY 'root-password';

4、创建mysql配置文件

1.my.cnf 文件优先级
/etc/my.cnf  #Global options
/etc/mysql/my.cnf  #Global options
SYSCONFDIR/my.cnf  #Global options
$MYSQL_HOME/my.cnf  #Server-specific options (server only)

2./etc/mysql/my.cnf
[client]
user = root
password = 123456
port = 3306
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
character-set-server = utf8mb4

5、重启mysql生效/etc/mysql/my.cnf

1.重启mysqld
/etc/init.d/mysqld restart
2.设置开机自启动mysqld
chkconfig --add mysqld
广告位
标签: