Centos7二进制安装Mysql5.7.36
1. 安装mysql程序运行的依赖
[root@VM-0-11-centos opt]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel perl vim numactl wget
2. 下载二进制的mysql5.7.36二进制包
[root@VM-0-11-centos opt]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz --no-check-certificate
3. 解压安装包到指定目录并更改所属用户
[root@VM-0-11-centos opt]# tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@VM-0-11-centos opt]# mv mysql-5.7.36-linux-glibc2.12-x86_64 /usr/local/mysql
[root@VM-0-11-centos local]# cd /usr/local/
[root@VM-0-11-centos local]# useradd -s /sbin/nologin mysql
[root@VM-0-11-centos local]# chown -R mysql.mysql /usr/local/mysql
[root@VM-0-11-centos local]# cp mysql/support-files/mysql.server /etc/init.d/mysqld
4. 更改启动命令的base_dir和data_dir
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
5. 修改mysqld的配置文件
[root@VM-0-11-centos local]# mv /etc/my.cnf /etc/my.cnf.bak
vim /etc/my.cnf
[client]
port = 3306
default-character-set=utf8mb4
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character-set-server=utf8mb4
default_storage_engine = InnoDB
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
6. 初始化mysqld,初始化后会出现一个随机临时密码 ,记得保存,比如我的就是H8)>6oFygaPM
[root@VM-0-11-centos local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7. 启动mysqld服务
[root@VM-0-11-centos local]# /etc/init.d/mysqld start
8. 查看进程和端口是否正常启动
9. 更改全局环境变量,方便mysql命令的执行
vim /etc/profile 增加
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@VM-0-11-centos local]# source /etc/profile
10. 利用初始化过程中自动生成的临时密码登录系统
[root@VM-0-11-centos local]# mysql -uroot -p