1、关系型数据库 MySQL
使用 yum 安装mysql
1、检查是否已经安装 Mysql
rpm -qa | grep mysql
如果安装了 就进行卸载
rpm -e mysql-community-libs-5.7.44-1.el7.x86_64
rpm -e mysql57-community-release-el7-11.noarch
rpm -e mysql-community-common-5.7.44-1.el7.x86_64
rpm -e mysql-community-client-5.7.44-1.el7.x86_64
rpm -e mysql-community-server-5.7.44-1.el7.x86_64
先停止 mysql的服务 systemctl stop mysqld
卸载 先卸载 : mysql-community-server 最后卸载 mysql-community-libs
2、在线下载安装MySQL
使用wget下载mysql
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
- 通过yum安装方法,会直接添加mysql环境变量和启动服务
yum -y install mysql57-community-release-el7-11.noarch.rpm # 安装基本的环境
已安装好
安装有问题
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or first to finish them. If those don’t work you’ll have to try removing/installing packages by hand (maybe package-cleanup can help).
我上次安装 后面卸载 有一个 “yum-complete-transaction --cleanup-only” and “yum history redo last”, 文件需要删除
这是最推荐的方法,用于完成或清理未完成的事务。
安装 yum-utils(如果尚未安装):
yum install yum-utils
清理未完成的事务:
yum-complete-transaction --cleanup-only
这会清除所有未完成的事务记录。
- 安装MySQL服务器:community-server
yum install -y mysql-community-server # 安装安装mysql服务
过程
3、启动服务并查看服务状态
systemctl start mysqld #启动服务
systemctl status mysqld #查看服务状态
4、获取MySQL服务密码
mysql 初始化 会有一个临时密码
登录成功后 必须先修改临时密码 然后才做后续操作
grep “password” /var/log/mysqld.log
5、登录修改密码
mysql -u root -p
修改密码
mysql> alter user 'root'@'localhost' identified by '123456';
flush privileges; # 修改密码刷新
mysql> grant all privileges on *.* to root@'%' identified by "123456";
6、密码忘记如何解决
1、停止 MySQL 服务systemctl stop mysqld
2、删除 MySQL 数据目录(请确保你知道你在做什么,因为这会导致数据丢失)rm -rf /var/lib/mysql
3、重新初始化 MySQL 数据库:mysqld --initialize --user=mysql
4、启动 MySQL 服务:mysqld --initialize --user=mysql
5、查看错误日志获取新的临时密码:grep 'temporary password' /var/log/mysqld.log
6、后续再次修改密码