centOS8安装MySql5.7

2021-07-30  本文已影响0人  孤好梦中敲代码

一、卸载MySql

卸载之前关闭所有mysql服务

systemctl stop mysqld

查看进程,还存在的话,直接kill

ps -ef | grep mysql
1.首先查看已安装的mysql
rpm -qa | grep -i mysql
[root@iZwz9dev0583p7pppda7ymZ ~]# rpm -qa | grep -i mysql
mysql-community-common-5.7.35-1.el7.x86_64
mysql-community-server-5.7.35-1.el7.x86_64
mysql-community-client-5.7.35-1.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-libs-5.7.35-1.el7.x86_64
2.逐个卸载掉
rpm -e mysql-community-common-5.7.35-1.el7.x86_64
rpm -e mysql-community-server-5.7.35-1.el7.x86_64
rpm -e mysql-community-client-5.7.35-1.el7.x86_64
rpm -e mysql-community-libs-5.7.35-1.el7.x86_64

mysql80-community-release-el7-3.noarch这是yum库的rpm包,如果版本符合,可以不卸载
注意:官网的mysql80-community-release-el8-1.noarch内只包含了mysql8.0以上版本,如果需要安装mysql5.7,需要使用mysql80-community-release-el7-3.noarch,el7表示操作系统版本linux7。

3. 卸载其他相关文件

1⃣️查找出来后使用rm -rf命令逐个删除

find / -name mysql

2⃣️或者直接使用如下命令删除

find / -name mysql -exec rm -rf {} \;

二、安装MySql

1.安装mysql的rpm源

centOS8中的yum库默认的是mariaDB,我们需要下载mysql80-community-release-el7-3.noarch,里面包含了5.6,5.7,8.0等版本。官网

wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

安装mysql的rmp

rpm -ivh mysql80-community-release-el7-3.noarch.rpm

查看将要安装的mysql相关文件

yum repolist all | grep mysql
[root@iZwz9dev0583p7pppda7ymZ ~]# yum repolist all | grep mysql
Repository epel is listed more than once in the configuration
mysql-cluster-7.5-community        MySQL Cluster 7.5 Community              禁用
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - Source     禁用
mysql-cluster-7.6-community        MySQL Cluster 7.6 Community              禁用
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - Source     禁用
mysql-cluster-8.0-community        MySQL Cluster 8.0 Community              禁用
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - Source     禁用
mysql-connectors-community         MySQL Connectors Community               启用
mysql-connectors-community-source  MySQL Connectors Community - Source      禁用
mysql-tools-community              MySQL Tools Community                    启用
mysql-tools-community-source       MySQL Tools Community - Source           禁用
mysql-tools-preview                MySQL Tools Preview                      禁用
mysql-tools-preview-source         MySQL Tools Preview - Source             禁用
mysql55-community                  MySQL 5.5 Community Server               禁用
mysql55-community-source           MySQL 5.5 Community Server - Source      禁用
mysql56-community                  MySQL 5.6 Community Server               禁用
mysql56-community-source           MySQL 5.6 Community Server - Source      禁用
mysql57-community                  MySQL 5.7 Community Server               启用
mysql57-community-source           MySQL 5.7 Community Server - Source      禁用
mysql80-community                  MySQL 8.0 Community Server               禁用
mysql80-community-source           MySQL 8.0 Community Server - Source      禁用

默认情况下mysql80-community是启用的,mysql57-community是禁用的,用以下命令改变将要安装的版本

yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community

如果出现yum-config-manager: command not found,安装yum的utils工具即可

yum -y install yum-utils

安装完再执行上一步

2.安装MySql
yum -y install mysql-community-server

如果遇到Error: Unable to find a match: mysql-community-server
先执行以下命令,关闭当前的MariaDB,再执行上面的安装命令

yum module disable mysql 

安装完毕,查看MySql版本

[root@iZwz9dev0583p7pppda7ymZ ~]# mysql --version
mysql  Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using  EditLine wrapper

启动MySql

systemctl start mysqld

查看MySql状态

[root@iZwz9dev0583p7pppda7ymZ ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-07-31 16:51:39 CST; 5h 57min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1585 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 1563 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1587 (mysqld)
    Tasks: 30 (limit: 23683)
   Memory: 228.7M
   CGroup: /system.slice/mysqld.service
           └─1587 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

7月 31 16:51:37 iZwz9dev0583p7pppda7ymZ systemd[1]: mysqld.service: Succeeded.
7月 31 16:51:37 iZwz9dev0583p7pppda7ymZ systemd[1]: Stopped MySQL Server.
7月 31 16:51:37 iZwz9dev0583p7pppda7ymZ systemd[1]: Starting MySQL Server...
7月 31 16:51:39 iZwz9dev0583p7pppda7ymZ systemd[1]: Started MySQL Server.

接下来是进入数据库,先查看数据库root用户的初始密码

grep "password" /var/log/mysqld.log

最后面冒号后的就是DNDcewvug3.-

[root@iZwz9dev0583p7pppda7ymZ ~]# grep "password" /var/log/mysqld.log
2021-07-31T08:26:01.664775Z 1 [Note] A temporary password is generated for root@localhost: DNDcewvug3.-

如果提示没有/var/log/mysqld.log或者sock之类的文件,重启服务器即可
通过以下命令进入数据库

mysql -uroot -p

更改root用户密码(不改的话无法进行其他操作)

ALTER USER USER() IDENTIFIED BY 'root';

密码设置太简单有可能出现ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看密码规则

SHOW VARIABLES LIKE 'validate_password%';
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 6     |#默认情况下这里是8
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |#默认情况下这里是MEDIUM
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

如果想要设置简单密码,可以更改规则中的长度和验证策略

set global validate_password_length=4;
set global validate_password_policy=0;

密码规则如下图


image.png

最后,就可以创建数据库了

create database testDB
上一篇下一篇

猜你喜欢

热点阅读