MySQL5.7编译安装(详细步骤)
1.下载软件
https://downloads.mysql.com/archives/community/
2.设置主机的yum源
root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [root@localhost yum.repos.d]# mkdir bak [root@localhost yum.repos.d]# mv *.repo bak [root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo --2022-09-17 11:13:03-- http://mirrors.aliyun.com/repo/Centos-7.repo 正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 183.201.220.248, 111.31.118.240, 111.51.82.238, ... 正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|183.201.220.248|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:2523 (2.5K) [application/octet-stream] 正在保存至: “/etc/yum.repos.d/CentOS-Base.repo” 100%[===============================================================================>] 2,523 --.-K/s 用时 0.001s 2022-09-17 11:13:08 (1.63 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
3.创建安装目录
[root@localhost ~]# mkdir -p /mysql/app
[root@localhost ~]# mkdir -p /mysql/data
4、创建用户组用户
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/nologin mysql
5、安装系统依赖的包
yum -y install gcc gcc-c++ make glibc automake autoconf libtool libssl-dev openssl openssl-devel ncurses-devel
6.安装cmake
[root@localhost ~]# wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz
[root@localhost app]# tar -zxvf cmake-3.5.2.tar.gz
[root@localhost app]# cd cmake-3.5.2/
[root@localhost cmake-3.5.2]# gmake
[root@localhost cmake-3.5.2]# gmake install
[root@localhost cmake-3.5.2]# cmake --version
cmake version 3.5.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
7、安装MySQL
一定要把命令拷贝到文本文档中.txt中,然后复制到命令行执行
[root@localhost app]# tar -zxvf mysql-boost-5.7.20.tar.gz
[root@localhost ~]# cd /mysql/app/mysql-5.7.20/
cmake . -DCMAKE_INSTALL_PREFIX=/mysql/app/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/mysql/app/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/mysql/app/mysql-5.7.20/boost/boost_1_59_0 \
-DWITH_SYSTEMD=1
以下是对命令的说明:
cmake . -DCMAKE_INSTALL_PREFIX=/mysql/app/mysql \ //指定mysql数据库安装目录
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ //连接文件位置
-DSYSCONFDIR=/etc \ //指定配置文件目录
-DSYSTEMD_PID_DIR=/mysql/app/mysql \ //进程文件目录
-DDEFAULT_CHARSET=utf8 \ //指定默认使用的字符集编码
-DDEFAULT_COLLATION=utf8_general_ci \ //指定默认使用的字符集校对规则
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ //存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ //存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ //存储引擎
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ //存储引擎
-DMYSQL_DATADIR=/usr/local/mysql/data \ //数据库文件
-DWITH_BOOST=/mysql/app/mysql-5.7.20/boost/boost_1_59_0 \ //指定Boost库的位置,mysql5.7必须添加该参数
-DWITH_SYSTEMD=1 //使系统支持MySQL数据库
完成后是这样的:
[root@localhost mysql-5.7.20]# make [root@localhost mysql-5.7.20]# make install
8、修改权限目录
[root@localhost ~]# chown -R mysql:mysql /mysql
9、配置环境变量
vi /etc/profile
export PATH=/mysql/app/mysql/bin:$PATH
[root@localhost ~]# source /etc/profile
10、修改配置文件
[mysqld] user=mysql basedir=/mysql/app/mysql datadir=/mysql/data socket=/tmp/mysql.sock server_id=6 port=3306 [mysql] socket=/tmp/mysql.sock
[root@localhost ~]# chown -R mysql:mysql /etc/my.cnf
11、初始化数据库
[root@localhost mysql]# mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data 2022-09-17T10:30:52.469934Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation
for more details). 2022-09-17T10:30:54.123200Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-09-17T10:30:54.417657Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-09-17T10:30:54.530740Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a
new UUID: cf4b3d50-3673-11ed-bba0-000c2937f544. 2022-09-17T10:30:54.533209Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-09-17T10:30:54.535661Z 1 [Note] A temporary password is generated for root@localhost: JKL7yd&ot1j!
12、启动数据库
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl status mysqld
13、登陆数据库
[root@localhost mysql]# mysql -uroot -p
14、修改密码
mysql> set password=PASSWORD('root'); Query OK, 0 rows affected, 1 warning (0.00 sec)