
目录
4、切换到mysql解压后目录下(/usr/local/mysql-8.0.27)
5、初始化mysql服务(切换到安装目录下:/usr/local/mysql-8.0.27执行下面命令
6.1复制mysql.server脚本到资源目录,并赋予执行权限:
这里,也可以用我现成的资源(百度网盘)。
链接:https://pan.baidu.com/s/1EQVwtvHPw7ejBM9a2zHy5g?pwd=9999 提取码:9999

libaio-0.3.109-13.el7.x86.rpm 包会用到。如果环境没有就需要安装。
也可以根据提示到官网去下载安装包
MySQL :: Download MySQL Community Server (Archived Versions)
https://downloads.mysql.com/archives/community/

注:这里我安装的是 Linux 版本
cat /etc/redhat-release
ldd --version



进入你的文件所在目录
cd /usr/local解压
tar -xvf mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz重命名
mv mysql-8.0.27-linux-glibc2.17-x86_64-minimal mysql-8.0.27touch /etc/my.cnf编辑mysql服务的配置文件
vim /etc/my.cnf注:此处用我得完整配置文件内容做示例,您只需修改其中的路径为自己的路径即可,或者您也可以设置成跟我一样的路径,那么配置文件可以直接使用。
my.cnf 文件内容如下:
[mysqld]
port=3306
basedir=/usr/local/mysql-8.0.27
datadir=/usr/local/mysql-8.0.27/data
socket=/usr/local/mysql-8.0.27/data/mysql.sock
character-set-server=utf8
collation-server=utf8_general_ci
#performance_schema_max_table_instances=400
#table_definition_cache=400
#table_open_cache=256
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
max_allowed_packet=1024M
max_connections=1000
# Recommended in standard MySQL setup
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
wait_timeout=2147483
interactive_timeout=2147483
connect_timeout=20
thread_cache_size=256
lower_case_table_names=1
innodb_strict_mode=0
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
innodb_file_per_table=1
log_bin_trust_function_creators=1
[mysqld_safe]
log-error=/usr/local/mysql-8.0.27/log/mysqld.log
pid-file=/usr/local/mysql-8.0.27/log/mysqld.pid
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysql.server]
default-character-set=utf8
[client]
default-character-set=utf8
socket=/usr/local/mysql-8.0.27/data/mysql.sock
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d创建存储数据的 data 目录和日志 log 目录
mkdir data
mkdir log
echo "" > /usr/local/mysql-8.0.27/log/mysqld.log ./bin/mysqld --initialize --user=root --basedir=/usr/local/mysql-8.0.27 --datadir=/usr/local/mysql-8.0.27/data可能会有这个报错信息:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

如果这一步报上面的错,提示缺少类库。可以采用在线或者离线安装依赖库来解决。
yum -y install libaio.so.1yum -y install numactl注:yum 安装比较简单,你只需要提示缺什么库,就安装什么类库。
CentOS 官网镜像地址:
CentOS Mirror

http://mirror.centos.org/ http://mirror.centos.org/centos/7/os/x86_64/Packages/
Tip:这里提示一下,如何找 rpm 离线包,根据目录结构。
contos : 代表系统
7:代表版本
os/x86_64:64位操作系统
Packages:rpm 包的路径
浏览器搜索 libaio ,点击下载

下载之后再上传到服务器上

切换目录到 /usr/local/mysql-8.0.27/rpm 下面,执行安装命令。
cd /usr/local/mysql-8.0.27/rpm
rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
yum 或者离线 安装完依赖库后,再重新执行初始化 mysql 服务的命令。
先切换到 mysql 安装目录下:/usr/local/mysql-8.0.27
cd /usr/local/mysql-8.0.27再执行初始化 mysql 服务的命令。
./bin/mysqld --initialize --user=root --basedir=/usr/local/mysql-8.0.27 --datadir=/usr/local/mysql-8.0.27/data这次执行完毕后,可以看到安装成功界面,此处会有默认临时密码,请务必记住,当然忘记了可以查询的。

初始化后会得到初始化的root登录密码:EAe>iXIqn2x/
先在 mysql 安装目录下,查看脚本中配置的基础路径是否正确
cd /usr/local/mysql-8.0.27vim ./support-files/mysql.serverbasedir=/usr/local/mysql-8.0.27
datadir=/usr/local/mysql-8.0.27/data
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqldchkconfig --add mysqld
chkconfig --list mysqld
service mysqld start这里启动可能的几种报错信息:
1)Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql-8.0.27/data/VM-0-16-centos.pid).
解决方案:编辑mysqld文件
vim /etc/rc.d/init.d/mysqld找到start模块,添加--user=root到mysqld_safe 后面即可

2)在 Red Hat Enterprise Linux Server release 7.9 (Maipo) 中提示如下信息:
/etc/init.d/mysqld: line 239: my_print_defaults: command not found /etc/init.d/mysqld: line 259: cd: /usr/local/mysql: No such file or directory Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[FAILED]ld_safe)
这里提示信息,是文件路径的错误。
解决方案:编辑mysqld文件,修改 basedir 和 datadir 的路径。
vim /etc/rc.d/init.d/mysqld注意修改下图中的这几个目录配置。

同时,找到 start 模块,添加 --user=root 到 mysqld_safe 后面。

不管哪种报错,我们就根据错误提示去做一些配置文件的修改即可。
再次执行启动命令
service mysqld start这次可以看到 Starting MySQL. SUCCESS!

或者看到 Starting MySQL.. [ OK ]

都是启动成功的输出信息。
打开/etc/profile配置文件,执行编辑文件命令
vim /etc/profile在文件末尾追加如下内容后:
MYSQL_HOME=/usr/local/mysql-8.0.27
export PATH=$PATH:$MYSQL_HOME/bin保存并退出(:wq)。
保存使得生效
source /etc/profile密码为初始化时生成的临时密码(EAe>iXIqn2x/)
mysql -uroot -p
注:初次安装完毕后,务必要修改密码,第一默认密码只是临时的,第二出于安全考虑以及自身需要。
alter user 'root'@'localhost' identified by '321qwe!@#';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';若是报错如下:
ERROR 1410 (42000): You are not allowed to create a user with GRANT

修改host,依次执行如下命令
use mysqlupdate user set host='%' where user='root';
再次授权执行两次
grant all on *.* to 'root'@'%' with grant option;
退出mysql
exit
此处我的服务器防火墙没有开启,所以3306端口可以直接连接。

如果您的服务器开启了防火墙,那么您在连接前需要开放3306端口,当然这个端口您也可以根据自己需要在my.cnf修改为特定端口号,主要也是安全起见。
执行如下编辑命令
vi /etc/sysconfig/iptables添加下面内容
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT保存退出(wq!)
重启防火墙
service iptables restart