前言
现在红帽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的教程