一、mysql8的安装包

链接:​​https://pan.baidu.com/s/1ZqMtOfwaImmQkhW7pH3Bzw ​​​​

提取码:tgjd

二、安装(我这里将软件放到了/opt目录下)

1、解压安装包
[root@zhixi opt]# tar -xvf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar

[root@zhixi opt]# ls
mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar mysql-community-libs-8.0.18-1.el7.x86_64.rpm
mysql-community-client-8.0.18-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm
mysql-community-common-8.0.18-1.el7.x86_64.rpm mysql-community-server-8.0.18-1.el7.x86_64.rpm
mysql-community-devel-8.0.18-1.el7.x86_64.rpm mysql-community-test-8.0.18-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm

2、移动安装包到指定目录
[root@zhixi opt]# mv ./*.rpm /usr/local/mysql/

3、安装软件包
3.1:第一个软件包
[root@zhixi mysql]# rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-8.0.18-1.e################################# [100%]

3.2:第二个软件包(报错了,
解决:在后面加上--force --nodeps即可)
[root@zhixi mysql]# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libcrypto.so.10()(64bit) is needed by mysql-community-libs-8.0.18-1.el7.x86_64
libcrypto.so.10(libcrypto.so.10)(64bit) is needed by mysql-community-libs-8.0.18-1.el7.x86_64
libssl.so.10()(64bit) is needed by mysql-community-libs-8.0.18-1.el7.x86_64
libssl.so.10(libssl.so.10)(64bit) is needed by mysql-community-libs-8.0.18-1.el7.x86_64
[root@zhixi mysql]# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm --force --nodeps
warning: mysql-community-libs-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.18-1.el7################################# [100%]

3.3:第三个软件包
[root@zhixi mysql]# rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm --force --nodeps
warning: mysql-community-client-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-8.0.18-1.e################################# [100%]

3.4:第四个软件包
[root@zhixi mysql]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm --force --nodeps
warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.18-1.e################################# [100%]
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update ttmpfiles.d/ drop-in file accordingly.

4、查看已经安装的mysql-rpm包
[root@zhixi mysql]# rpm -qa | grep mysql
mysql-community-client-8.0.18-1.el7.x86_64
mysql-community-libs-8.0.18-1.el7.x86_64
mysql-community-server-8.0.18-1.el7.x86_64
mysql-community-common-8.0.18-1.el7.x86_64
#卸载已安装的mysql-rpm包命令
rpm  -e 软件包名 --nodeps


 三、初始化

1、找到mysql服务的安装地址进行初始化操作
[root@zhixi sbin]# find / -name mysqld
/run/mysqld
/usr/sbin/mysqld

2、进入到mysqld服务的目录下
[root@zhixi sbin]# cd /run/mysqld/

3、初始化mysql服务,出错
解决办法:rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm
root@zhixi mysqld]# mysqld --initialize
mysqld: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory
[root@zhixi mysqld]# wget http://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm
--2022-01-27 14:44:08-- http://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm
Resolving mirror.centos.org (mirror.centos.org)... 13.233.140.107, 2401:78c0::e00e
Connecting to mirror.centos.org (mirror.centos.org)|13.233.140.107|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1186088 (1.1M) [application/x-rpm]
Saving to: ‘compat-openssl10-1.0.2o-3.el8.x86_64.rpm’
compat-openssl10-1.0.2o-3.el8.x86_64. 100%[======================================================================>] 1.13M 1.28MB/s in 0.9s
2022-01-27 14:44:10 (1.28 MB/s) - ‘compat-openssl10-1.0.2o-3.el8.x86_64.rpm’ saved [1186088/1186088]
#解决上面报错的问题
[root@zhixi mysqld]# rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm

#重新执行初始化mysql服务
[root@zhixi sbin]# mysqld --initialize


4、授权
[root@zhixi sbin]# chown mysql:mysql /var/lib/mysql -R

5、开启mysql服务
[root@zhixi sbin]# systemctl start mysqld
[root@zhixi sbin]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor p>
Active: active (running) since Thu 2022-01-27 14:45:28 CST; 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 28371 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, stat>
Main PID: 28403 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 10751)
Memory: 421.0M
CGroup: /system.slice/mysqld.service
└─28403 /usr/sbin/mysqld

Jan 27 14:45:07 zhixi systemd[1]: Starting MySQL Server...
Jan 27 14:45:28 zhixi systemd[1]: Started MySQL Server.

6、查看root初始密码
[root@zhixi sbin]# cat /var/log/mysqld.log | grep password
2022-01-27T06:44:35.795688Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hca5)wXdt3yI


四、修改密码以及开启远程访问

1、登录进去mysql
[root@zhixi sbin]# mysql -u root -p
……这边输入默认密码,进行登录

2、修改mysql的密码
mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "自己要设置的密码";
Query OK, 0 rows affected (0.01 sec)

3、使操作立即生效
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

4、进入mysql目录,开放远程访问方面的权限
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

5、使操作立即生效
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit


五、开启端口与重启防火墙

1、开启防火墙
[root@zhixi sbin]# systemctl restart firewalld

2、开放mysql对外访问的端口
[root@zhixi sbin]# firewall-cmd --zone=public --add-port=3306/tcp --permanent


连接成功:

Linux下MySQL(8.0.18)的安装_f5