CentOS搭建MySQL环境问题总结

一、卸载默认安装的mariadb

在安装MySQL之前,需要注意先卸载mariadb

yum search mysql
yum remove mariadb.x86_64

但是我在执行第一个命令的时候有如下提示:

[root@localhost ~]# yum search mysql
已加载插件:fastestmirror, langpacks
/var/run/yum.pid 已被锁定,PID 为 9607 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:131 M RSS (556 MB VSZ)
    已启动: Wed Jun 15 14:42:48 2022 - 06:40之前
    状态  :睡眠中,进程ID:9607
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:131 M RSS (556 MB VSZ)
    已启动: Wed Jun 15 14:42:48 2022 - 06:42之前
    状态  :睡眠中,进程ID:9607
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:131 M RSS (556 MB VSZ)
    已启动: Wed Jun 15 14:42:48 2022 - 06:52之前
    状态  :睡眠中,进程ID:9607
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:131 M RSS (556 MB VSZ)
    已启动: Wed Jun 15 14:42:48 2022 - 06:54之前
    状态  :睡眠中,进程ID:9607
Another app is currently holding the yum lock; waiting for it to exit...
^C

Exiting on user cancel.
[root@localhost ~]# ^C

我按了CTRL C才结束,不然一直输出,这里很明显是PID(端口) 为 9607 的另一个程序正在运行。
这里我直接去网上找了下解决方法:
输入以下命令:

rm -f /var/run/yum.pid

解决了上面的端口占用的问题(执行下面命令之后是没有反应的)。

[root@localhost ~]# rm -f /var/run/yum.pid

接下来就可以正常执行命令了:

yum search mysql
yum remove mariadb.x86_64

效果如下所示:

[root@localhost ~]# yum search mysql
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
============================== N/S matched: mysql ==============================
MySQL-python.x86_64 : An interface to MySQL
akonadi-mysql.x86_64 : Akonadi MySQL backend support
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
dovecot-mysql.x86_64 : MySQL back end for dovecot
freeradius-mysql.x86_64 : MySQL support for freeradius
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
mysql-connector-java.noarch : Official JDBC driver for MySQL
mysql-connector-odbc.x86_64 : ODBC driver for MySQL
pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
qt-mysql.i686 : MySQL driver for Qt's SQL classes
qt-mysql.x86_64 : MySQL driver for Qt's SQL classes
qt3-MySQL.i686 : MySQL drivers for Qt 3's SQL classes
qt3-MySQL.x86_64 : MySQL drivers for Qt 3's SQL classes
qt5-qtbase-mysql.i686 : MySQL driver for Qt5's SQL classes
qt5-qtbase-mysql.x86_64 : MySQL driver for Qt5's SQL classes
redland-mysql.x86_64 : MySQL storage support for Redland
rsyslog-mysql.x86_64 : MySQL support for rsyslog
mariadb.x86_64 : A community developed branch of MySQL
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients

  名称和简介匹配 only,使用“search all”试试。
[root@localhost log]# rpm -qa|grep mariadb

二、安装MySQLl8.0 的yum资源库

yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

效果如下:

[root@localhost ~]# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
已加载插件:fastestmirror, langpacks
mysql80-community-release-el7-1.noarch.rpm               |  25 kB     00:00     
正在检查 /var/tmp/yum-root-Jt9Sus/mysql80-community-release-el7-1.noarch.rpm: mysql80-community-release-el7-1.noarch
/var/tmp/yum-root-Jt9Sus/mysql80-community-release-el7-1.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql80-community-release.noarch.0.el7-1 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package             架构   版本  源                                       大小
================================================================================
正在安装:
 mysql80-community-release
                     noarch el7-1 /mysql80-community-release-el7-1.noarch  31 k

事务概要
================================================================================
安装  1 软件包

总计:31 k
安装大小:31 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : mysql80-community-release-el7-1.noarch                      1/1 
  验证中      : mysql80-community-release-el7-1.noarch                      1/1 

已安装:
  mysql80-community-release.noarch 0:el7-1                                      

完毕!

三、安装MySQL8.0

yum install mysql-community-server

使用上面的命令的时候,会安装失败,按了y之后,会有这样的信息:

[root@localhost ~]# yum install mysql-community-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
......
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥

源 "MySQL 8.0 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。

我在网上看到了这样的解决方案:
也就是在前面加上sudo来获取管理员权限:

sudo yum install mysql-server --nogpgcheck

效果如下:

[root@localhost ~]# sudo yum install mysql-server --nogpgcheck
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
正在解决依赖关系
--> 正在检查事务
......

事务概要
================================================================================
安装  3 软件包 (+4 依赖软件包)

总计:75 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
......
已安装:
  mysql-community-libs.x86_64 0:8.0.29-1.el7                                    
  mysql-community-libs-compat.x86_64 0:8.0.29-1.el7                             
  mysql-community-server.x86_64 0:8.0.29-1.el7                                  

作为依赖被安装:
  mysql-community-client.x86_64 0:8.0.29-1.el7                                  
  mysql-community-client-plugins.x86_64 0:8.0.29-1.el7                          
  mysql-community-common.x86_64 0:8.0.29-1.el7                                  
  mysql-community-icu-data-files.x86_64 0:8.0.29-1.el7                                                                

完毕!

四、启动MySQL服务和设置MySQL自动启动

systemctl start mysqld
systemctl enable mysqld

下面命令执行之后没有任何反应:

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enable mysqld

五、查看MySQL默认密码

grep 'temporary password' /var/log/mysqld.log

效果如下:

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2022-06-15T06:54:17.679112Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &G&6_klshOJg

默认密码是:&G&6_klshOJg

六、进入MySQL并重置密码

进入MySQL命令:

mysql -uroot -p

并将上面的默认密码&G&6_klshOJg输入,效果如下:

[root@localhost log]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.29 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> 

现在,不管你输入什么MySQL命令,都会有以下报错:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

上面的报错信息说明我们需要重置密码,我花了很多时间尝试修改密码,命令如下:

alter user user() identified by '123qweR';

就是没法修改这个密码,因为这不符合密码规范:

mysql> alter user user() identified by '123qweR';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

于是我安装它原来密码的格式来修改密码:

alter user user() identified by '&G&6_zlt';

就成功了!
效果如下:

mysql> alter user user() identified by '&G&6_zlt';
Query OK, 0 rows affected (0.00 sec)

有点离谱,但是我也没什么办法,花了挺多时间的了。
之后我们使用MySQL数据库的时候就不会让你再去修改密码了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值