前言
現在紅帽Linux上默認是沒有yum源的
yum軟件倉庫裏面只有MariaDB的安裝包所以我們需要自己先配置yum源
實驗準備(以下操作在VMware中進行)
一臺Linux主機 (我這裏用的是RHEL7.4)
已經聯網
不要掛載yum鏡像
1、配置yum源
下載yum源(我這裏已經找好了)
wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
yum源下載鏈接:MySQL
安裝yum源
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
查看有哪些版本的mysql
yum repolist all | grep mysql
2、安裝
yum install -y mysql-community-server
3、啓動mysql
注意啓動的時候是mysqld而不是mysql
systemctl start mysqld
查看狀態
systemctl status mysqld
4、登錄數據庫,修改數據庫密碼
找到密碼: 紅框的地方就是密碼
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2020-12-18T15:15:55.572640Z 1 [Note] A temporary password is generated for root@localhost: 9sX3oDXGti)P
密碼:9sX3oDXGti)P
5、登錄MySQL
[root@localhost ~]# mysql -uroot -p'9sX3oDXGti)P'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>show databases; ---這裏會報錯,需要重新修改密碼
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXGC.lab123';
Query OK, 0 rows affected (0.01 sec) ---表示修改成功
刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
退出
mysql> exit
6、使用新密碼登錄數據庫
[root@localhost ~]# mysql -uroot -p'XXGC.lab123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> show databses;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
以上就是在RHEL7.4中配置MySQL的教程