赞
踩
1、下载网址:www.mysql.com和www.oracle.com
1)点击DOWNLOADS
2)翻到最下面,点击MySQL Commounity (GPL)Downloads
3)点击MySQL Commounity Server
4)点击Archives
5)选择自己需要的mysql版本,选择自己的操作系统版本
2、下载软件包:
[root@192 mysql]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-8.0.27-1.el7.x86_64.rpm
[root@192 mysql]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-8.0.27-1.el7.x86_64.rpm
[root@192 mysql]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm
[root@192 mysql]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-8.0.27-1.el7.x86_64.rpm
[root@192 mysql]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-8.0.27-1.el7.x86_64.rpm
注:这5个rpm包包括了服务端的包和客户端的包,同时也包含了依赖包。
# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-5.7.30-1.el7.x86_64.rpm
# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-5.7.30-1.el7.x86_64.rpm
# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-5.7.30-1.el7.x86_64.rpm
# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.30-1.el7.x86_64.rpm
2、下载依赖软件
[root@192 mysql]# yum install -y net-tools.x86_64 libaio.x86_64 perl.x86_64
3、安装Mysql服务器
[root@192 mysql]# rpm -ivh mysql-community-*
警告:mysql-community-client-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
mariadb-libs 被 mysql-community-libs-8.0.27-1.el7.x86_64 取代
发现有一个报错,mariadb-libs 被 mysql-community-libs-8.0.27-1.el7.x86_64 取代,所以要移除mariadb-libs 。
[root@192 mysql]# yum -y remove mariadb-libs
[root@192 mysql]# rpm -ivh mysql-community-*
警告:mysql-community-client-8.0.27-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-8.0.27-1.e################################# [ 20%]
2:mysql-community-client-plugins-8.################################# [ 40%]
3:mysql-community-libs-8.0.27-1.el7################################# [ 60%]
4:mysql-community-client-8.0.27-1.e################################# [ 80%]
5:mysql-community-server-8.0.27-1.e################################# [100%]
4、启动mysql,并设置开机启动
[root@192 mysql]# systemctl start mysqld
[root@192 mysql]# systemctl enable mysqld
[root@192 mysql]# systemctl status mysqld
5、查看默认密码,并修改
1)查看默认密码
[root@192 mysql]# grep 'password' /var/log/mysqld.log
2022-01-23T01:36:10.004318Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _:8JTG7hMmh6
2)修改密码
[root@192 mysql]# mysqladmin -uroot -p'_:8JTG7hMmh6' password 'Jiaofan@123'
[root@192 mysql]# mysql -u root -p'Jiaofan@123'
1、下载源码包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.27-el7-x86_64.tar.gz
2、安装依赖包
1)编译环境依赖
yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make
cmake需要安装 3.5.1 的高版本,yum -y install cmake 安装的是 2.8.12.2 版本,低版本编译mysql-8.0 会报错。
2)cmake的官网:https://cmake.org/
[root@localhost ~]# wget https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1.tar.gz
[root@localhost ~]# cd cmake-3.22.1
[root@localhost ~]# ./configure
[root@localhost ~]# gmake && gmake install
设置cmake的环境变量
[root@localhost ~]# vi /etc/profile
export CMAKE_HOME=/root/cmake-3.22.1
export PATH=${CMAKE_HOME}/bin:$PATH
[root@localhost ~]# source /etc/profile
[root@localhost ~]# cmake -version
cmake version 3.22.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
3)安装devtoolset-10-gcc、devtoolset-10-gcc-c++和devtoolset-10-binutils
yum -y install centos-release-scl
yum -y install devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutils
3、开始进行安装
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql
[root@localhost ~]# cd mysql-8.0.27
[root@localhost mysql-8.0.27]# mkdir bld
[root@localhost mysql-8.0.27]# cd bld
[root@localhost bld]# cmake . -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/boost -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DINSTALL_MANDIR=/usr/share/man -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
注:编译安装mysql-5.7的时候boost是需要下载安装的,但是mysql-8.0指定 -DDOWNLOAD_BOOST=1 之后会自动下载到 -DWITH_BOOST=/root/boost 指定的目录内,长时间等待以后编译安装就可以完成了。
4、初始化动作
#创建mysql的用户 [root@localhost mysql]# cd /usr/local/mysql #官网说明必须创建mysql-files文件 [root@localhost mysql]# mkdir mysql-files [root@localhost mysql]# chown mysql:mysql mysql-files [root@localhost mysql]# chmod 750 mysql-files #进行初始化 [root@localhost mysql]# bin/mysqld --initialize --user=mysql # 屏幕会出来密码,注意保存。 [root@localhost mysql]# bin/mysql_ssl_rsa_setup [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld #开启服务 [root@localhost mysql]# /etc/init.d/mysqld start #测试 [root@localhost bin]# ./mysql -uroot -p Enter password:
5、设置mysql的环境变量
[root@localhost bin]# vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=${MYSQL_HOME}/bin:$PATH
[root@localhost bin]# source /etc/profile
6、用 systemctl 管理编译安装的 mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld #前面已经执行过了 [root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# chkconfig mysqld on [root@localhost ~]# chkconfig --list | grep mysqld 注:该输出结果只显示 SysV 服务,并不包含 原生 systemd 服务。SysV 配置数据 可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。 查看在具体 target 启用的服务请执行 'systemctl list-dependencies [target]'。 mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关 #启动mysql方法一: [root@localhost ~]# mysqld_safe --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql 2022-01-25T08:04:04.048599Z mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 2022-01-25T08:04:04.086843Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data 2022-01-25T08:04:05.627720Z mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended #启动mysql方法二: [root@localhost local]# service mysqld start Starting MySQL.. SUCCESS!
7、报错处理
报错一:cmake版本太低,
-- Running cmake version 2.8.12.2
CMake Warning at CMakeLists.txt:82 (MESSAGE):
Please use cmake3 rather than cmake on this platform
-- Please install cmake3 (yum install cmake3)
CMake Error at CMakeLists.txt:112 (CMAKE_MINIMUM_REQUIRED):
CMake 3.5.1 or higher is required. You are running version 2.8.12.2
-- Configuring incomplete, errors occurred!
解决方案:
下载最近的包安装,上面有下载安装cmake的过程
报错二:
-- Running cmake version 3.22.1 -- Could NOT find Git (missing: GIT_EXECUTABLE) -- This is .el7. as found from 'rpm -qf /' -- Looking for a devtoolset compiler CMake Warning at CMakeLists.txt:347 (MESSAGE): Could not find devtoolset compiler/linker in /opt/rh/devtoolset-10 CMake Warning at CMakeLists.txt:349 (MESSAGE): You need to install the required packages: yum install devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutils CMake Error at CMakeLists.txt:351 (MESSAGE): Or you can set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly. -- Configuring incomplete, errors occurred!
解决办法:
yum -y install centos-release-scl
yum -y install devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutils
注:按我上面的安装步骤来,不会遇到这两个报错。
报错三:
Starting MySQL.2022-01-25T07:05:47.634711Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
解决办法:
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb
报错四:
Starting MySQL.2022-01-25T07:11:40.629863Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
解决办法:
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
报错五:
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
解决办法
注:由于我的虚拟机的新的,最后发现是 /usr/local/mysql57/data 目录没有创建。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。