Linux-安装-MySQL5.7
1、二进制安装MySQL5.7
安装相关包
yum -y install libaio numactl-libs
用户和组
groupadd mysql useradd -r -g mysql -s /bin/false mysql

[root@centos7-liyj ~]#groupadd mysql [root@centos7-liyj ~]#useradd -r -g mysql -s /bin/false mysql #创建系统用户 [root@centos7-liyj ~]#tail /etc/passwd ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin liyanjin:x:1000:1000:liyanjin:/home/liyanjin:/bin/bash tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin mysql:x:998:1001::/home/mysql:/bin/false
下载二进制程序文件
下载路径http://mirrors.163.com/mysql/Downloads/MySQL-5.7/
Linux系统中:http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
准备程序文件
[root@centos7-liyj ~]#tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@centos7-liyj ~]#cd /usr/local/ [root@centos7-liyj /usr/local]#ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql [root@centos7-liyj /usr/local]#chown -R root.root /usr/local/mysql/ [root@centos7-liyj /usr/local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@centos7-liyj /usr/local]#. /etc/profile.d/mysql.sh

修改前文件内容属组属主 [root@centos7-liyj /usr/local/mysql]#ll total 272 drwxr-xr-x 2 root root 4096 May 10 09:37 bin drwxr-xr-x 2 root root 55 May 10 09:37 docs drwxr-xr-x 3 root root 4096 May 10 09:37 include drwxr-xr-x 5 root root 230 May 10 09:37 lib -rw-r--r-- 1 7161 31415 259253 Nov 30 04:09 LICENSE drwxr-xr-x 4 root root 30 May 10 09:37 man -rw-r--r-- 1 7161 31415 566 Nov 30 04:09 README drwxr-xr-x 28 root root 4096 May 10 09:37 share drwxr-xr-x 2 root root 90 May 10 09:37 support-files 修改后文件内容属组属主 [root@centos7-liyj /usr/local/mysql]#ll total 272 drwxr-xr-x 2 root root 4096 May 10 09:37 bin drwxr-xr-x 2 root root 55 May 10 09:37 docs drwxr-xr-x 3 root root 4096 May 10 09:37 include drwxr-xr-x 5 root root 230 May 10 09:37 lib -rw-r--r-- 1 root root 259253 Nov 30 04:09 LICENSE drwxr-xr-x 4 root root 30 May 10 09:37 man -rw-r--r-- 1 root root 566 Nov 30 04:09 README drwxr-xr-x 28 root root 4096 May 10 09:37 share drwxr-xr-x 2 root root 90 May 10 09:37 support-files
准备环境变量
[root@centos7-liyj /usr/local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@centos7-liyj /usr/local]#. /etc/profile.d/mysql.sh
准备配置文件
[root@centos7-liyj /usr/local]#cp /etc/my.cnf{,.bak} [root@centos7-liyj /usr/local]#vim /etc/my.cnf [mysqld] datadir=/data/mysql skip_name_resolve=1 socket=/data/mysql/mysql.sock log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid [client] socket=/data/mysql/mysql.sock
初始化数据库文件并提取root密码
[root@centos7-liyj /data]#mysqld --initialize --user=mysql --datadir=/data/mysql [root@centos7-liyj /data/mysql]#awk '/temporary password/{print $NF}' /data/mysql/mysql.log Bu_jLT.yr8,y

[root@centos7-liyj /data]#cd mysql/ [root@centos7-liyj /data/mysql]#ll total 110664 -rw-r----- 1 mysql mysql 56 May 10 10:26 auto.cnf -rw------- 1 mysql mysql 1680 May 10 10:26 ca-key.pem -rw-r--r-- 1 mysql mysql 1112 May 10 10:26 ca.pem -rw-r--r-- 1 mysql mysql 1112 May 10 10:26 client-cert.pem -rw------- 1 mysql mysql 1676 May 10 10:26 client-key.pem -rw-r----- 1 mysql mysql 436 May 10 10:26 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 May 10 10:26 ibdata1 -rw-r----- 1 mysql mysql 50331648 May 10 10:26 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 May 10 10:26 ib_logfile1 drwxr-x--- 2 mysql mysql 4096 May 10 10:26 mysql -rw-r----- 1 mysql mysql 1108 May 10 10:26 mysql.log drwxr-x--- 2 mysql mysql 8192 May 10 10:26 performance_schema -rw------- 1 mysql mysql 1680 May 10 10:26 private_key.pem -rw-r--r-- 1 mysql mysql 452 May 10 10:26 public_key.pem -rw-r--r-- 1 mysql mysql 1112 May 10 10:26 server-cert.pem -rw------- 1 mysql mysql 1680 May 10 10:26 server-key.pem drwxr-x--- 2 mysql mysql 8192 May 10 10:26 sys [root@centos7-liyj /data/mysql]#cat mysql.log 2022-05-10T02:26:08.549541Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-05-10T02:26:08.668742Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-05-10T02:26:08.689686Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-05-10T02:26:08.743917Z 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: 8d1ce2f2-d008-11ec-8556-005056399ee0. 2022-05-10T02:26:08.745068Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-05-10T02:26:09.353933Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-05-10T02:26:09.353947Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-05-10T02:26:09.354427Z 0 [Warning] CA certificate ca.pem is self signed. 2022-05-10T02:26:09.459455Z 1 [Note] A temporary password is generated for root@localhost: Bu_jLT.yr8,y
方式2: 生成 root 空密码
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
准备服务脚本和启动
[root@centos7-liyj /data/mysql]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@centos7-liyj /data/mysql]#chkconfig --add mysqld [root@centos7-liyj /data/mysql]#systemctl start mysqld

[root@centos7-liyj /data/mysql]#ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 80 [::]:3306 [::]:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 100 [::1]:25 [::]:* LISTEN 0 128 [::1]:6010 [::]:* LISTEN 0 128 [::1]:6011 [::]:*

[root@centos7-liyj ~]#ps aux | tail -10 root 1335 0.0 0.0 0 0 ? S 10:30 0:00 [kworker/1:0] root 1373 0.0 0.0 115544 1708 ? S 10:32 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid mysql 1525 0.0 8.5 1184924 173180 ? Sl 10:32 0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/mysql.pid --socket=/data/mysql/mysql.sock root 1573 0.0 0.0 0 0 ? S 10:33 0:00 [kworker/1:3] root 1574 0.0 0.0 0 0 ? S 10:33 0:00 [kworker/0:1] root 1582 0.0 0.1 135728 3312 pts/1 S+ 10:37 0:00 mysql -uroot -px xxxxxxxxx root 1583 0.0 0.0 0 0 ? S 10:38 0:00 [kworker/1:1] root 1584 0.0 0.0 0 0 ? S 10:38 0:00 [kworker/0:0] root 1595 0.0 0.0 155452 1876 pts/0 R+ 10:53 0:00 ps aux root 1596 0.0 0.0 108092 696 pts/0 R+ 10:53 0:00 tail -10
修改口令---修改前面生成的随机密码为指定密码 [root@centos7-liyj /data/mysql]#mysqladmin -uroot -p'Bu_jLT.yr8,y' password atech123456 mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. 登录测试 [root@centos7-liyj /data/mysql]#mysql -uroot -patech123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
#修改前面生成的空密码为指定密码
mysqladmin -uroot password atech123456
2.编译安装MySQL5.7
安装相关依赖包
yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper
准备用户和数据目录
[root@mysql-lyj ~]#useradd -r -s /sbin/nologin -d /data/mysql mysql [root@mysql-lyj /data]#mkdir /data/mysql [root@mysql-lyj /data]#chown mysql.mysql /data/mysql/ drwxr-xr-x 2 mysql mysql 6 May 10 10:59 mysql
创建程序安装目录
[root@mysql-lyj]#mkdir /usr/local/mysql
下载编译安装包MySQL5.7
[root@mysql-lyj ~]#wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37.tar.gz --2022-05-10 12:51:01-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37.tar.gz Resolving downloads.mysql.com (downloads.mysql.com)... 137.254.60.14 Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.37.tar.gz [following] --2022-05-10 12:51:03-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.37.tar.gz Resolving cdn.mysql.com (cdn.mysql.com)... 23.56.29.233 Connecting to cdn.mysql.com (cdn.mysql.com)|23.56.29.233|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 56248775 (54M) [application/x-tar-gz] Saving to: ‘mysql-5.7.37.tar.gz’ 100%[=====================================================================>] 56,248,775 17.7MB/s in 3.0s 2022-05-10 12:51:07 (17.7 MB/s) - ‘mysql-5.7.37.tar.gz’ saved [56248775/56248775]
解压缩文件
[root@mysql-lyj ~]#tar xf mysql-5.7.37.tar.gz -C /usr/local/src
[root@mysql-lyj ~]#cd /usr/local/src/
[root@mysql-lyj /usr/local/src]#cd mysql-5.7.37/
进入screen模式,编译安装时间较长,防止远程进程中断,导致安装不成功
[root@mysql-lyj /usr/local/src]#cd mysql-5.7.37/ [root@centos7-liyj /usr/local/src/mysql-5.7.37]#cmake . \ > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \ > -DMYSQL_DATADIR=/data/mysql/ \ > -DSYSCONFDIR=/etc/ \ > -DMYSQL_USER=mysql \ > -DWITH_BOOST=/usr/local/boost \ #未指定有报错提示 > -DWITH_INNOBASE_STORAGE_ENGINE=1 \ > -DDOWNLOAD_BOOST=1 \ #未指定有报错提示 > -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ > -DWITH_PARTITION_STORAGE_ENGINE=1 \ > -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \ > -DWITH_DEBUG=0 \ > -DWITH_READLINE=1 \ > -DWITH_SSL=system \ > -DWITH_ZLIB=system \ > -DWITH_LIBWRAP=0 \ > -DENABLED_LOCAL_INFILE=1 \ > -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_general_ci

[root@mysql-lyj /usr/local/src/mysql-5.7.37]#cmake . \ > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \ > -DMYSQL_DATADIR=/data/mysql/ \ > -DSYSCONFDIR=/etc/ \ > -DMYSQL_USER=mysql \ > -DWITH_INNOBASE_STORAGE_ENGINE=1 \ > -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ > -DWITH_PARTITION_STORAGE_ENGINE=1 \ > -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \ > -DWITH_DEBUG=0 \ > -DWITH_READLINE=1 \ > -DWITH_SSL=system \ > -DWITH_ZLIB=system \ > -DWITH_LIBWRAP=0 \ > -DENABLED_LOCAL_INFILE=1 \ > -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_general_ci -- Running cmake version 2.8.12.2 -- Could NOT find Git (missing: GIT_EXECUTABLE) -- Configuring with MAX_INDEXES = 64U -- The C compiler identification is GNU 4.8.5 -- The CXX compiler identification is GNU 4.8.5 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- CMAKE_GENERATOR: Unix Makefiles -- Looking for SHM_HUGETLB -- Looking for SHM_HUGETLB - found -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of void * -- Check size of void * - done -- SIZEOF_VOIDP 8 -- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG -- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG - Failed -- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG -- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG - Failed -- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD -- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD - Failed -- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD -- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD - Failed -- Performing Test HAVE_C_FP_CONTRACT_FLAG -- Performing Test HAVE_C_FP_CONTRACT_FLAG - Success -- Performing Test HAVE_CXX_FP_CONTRACT_FLAG -- Performing Test HAVE_CXX_FP_CONTRACT_FLAG - Success -- MySQL 5.7.37 -- Packaging as: mysql-5.7.37-Linux-x86_64 -- Found /usr/include/boost/version.hpp -- BOOST_VERSION_NUMBER is #define BOOST_VERSION 105300 CMake Warning at cmake/boost.cmake:273 (MESSAGE): Boost minor version found is 53 we need 59 Call Stack (most recent call first): CMakeLists.txt:536 (INCLUDE) -- BOOST_INCLUDE_DIR /usr/include -- LOCAL_BOOST_DIR -- LOCAL_BOOST_ZIP -- Could not find (the correct version of) boost. -- MySQL currently requires boost_1_59_0 CMake Error at cmake/boost.cmake:88 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory> This CMake script will look for boost in <directory>. If it is not there, it will download and unpack it (in that directory) for you. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 Call Stack (most recent call first): cmake/boost.cmake:276 (COULD_NOT_FIND_BOOST) CMakeLists.txt:536 (INCLUDE) -- Configuring incomplete, errors occurred! See also "/usr/local/src/mysql-5.7.37/CMakeFiles/CMakeOutput.log". See also "/usr/local/src/mysql-5.7.37/CMakeFiles/CMakeError.log".
cmake 解析文件报错
CMake Error at cmake/boost.cmake:194 (MESSAGE): You can try downloading http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz manually using curl/wget or a similar tool Call Stack (most recent call first): CMakeLists.txt:507 (INCLUDE) -- Configuring incomplete, errors occurred! See also "/home/soft/mysql-5.7.24/CMakeFiles/CMakeOutput.log". See also "/home/soft/mysql-5.7.24/CMakeFiles/CMakeError.log".
解决问题
https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
下载boost_1_59_0.tar.gz 包
传送到Linux系统,
解压缩到 /usr/local/boost目录下
[root@centos7-liyj ~]#tar xf boost_1_59_0.tar.gz -C /usr/local/boost
删除mysql-5.7.36目录下的CMakeCache.txt
[root@centos7-liyj /usr/local/src/mysql-5.7.37]#rm -f CMakeCache.txt
1 2 3 | 再次执行 cmake 命令就完成编译了 在执行,make&&make install 完成安装 |
准备环境变量
[root@centos7-liyj ~]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@centos7-liyj ~]#. /etc/profile.d/mysql.sh
准备配置文件
[root@centos7-liyj /data/mysql]#cp /etc/my.cnf{,.back} [root@centos7-liyj ~]#vim /etc/my.cnf [mysqld] datadir=/data/mysql skip_name_resolve=1 socket=/data/mysql/mysql.sock log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid [client] socket=/data/mysql/mysql.sock
初始化数据库文件并提取root密码
[root@centos7-liyj /usr/local/mysql]#bin/mysqld --initialize --user=mysql --datadir=/data/mysql [root@centos7-liyj /usr/local/mysql]#awk '/temporary password/{print $NF}' /data/mysql/mysql.log ?put%=%qu0lH
准备服务脚本和启动
[root@centos7-liyj /usr/local/mysql]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@centos7-liyj /usr/local/mysql]#chkconfig --add mysqld [root@centos7-liyj /usr/local/mysql]#systemctl start mysqld
修改口令
[root@centos7-liyj ~]#mysqladmin -uroot -p'?put%=%qu0lH' password atech123456 mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
登录测试
[root@centos7-liyj ~]#mysql -uroot -patech123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.37 Source distribution Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)