1)检查当前系统是否安装过Mysql
[haha@hadoop102 ~]$ rpm -qa|grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 //如果存在通过如下命令卸载 [haha @hadoop102 ~]$ sudo rpm -e --nodeps mariadb-libs //用此命令卸载mariadb2)将MySQL安装包拷贝到/opt/module目录下
[haha @hadoop102 software]# ll 总用量 528384 -rw-r--r--. 1 root root 609556480 3月 21 15:41 mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar3)解压MySQL安装包
[haha @hadoop102 software]# tar -xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar4)在安装目录下执行rpm安装
注意:按照顺序依次执行
commonlibslibs-compatclientserver [haha @hadoop102 software]$ sudo rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm [haha @hadoop102 software]$ sudo rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm [haha @hadoop102 software]$ sudo rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm [haha @hadoop102 software]$ sudo rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm [haha @hadoop102 software]$ sudo rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm5)删除/etc/my.cnf文件中datadir指向的目录下的所有内容,如果有内容的情况下:
[haha @hadoop102 mysql]# cd /var/lib/mysql [haha @hadoop102 mysql]# sudo rm -rf ./* //注意执行命令的位置6)初始化数据库
[haha @hadoop102 opt]$ sudo mysqld --initialize --user=mysql7)查看临时生成的root用户的密码
[haha @hadoop102 opt]$ sudo cat /var/log/mysqld.log8)启动MySQL服务
[haha @hadoop102 opt]$ sudo systemctl start mysqld9)登录MySQL数据库
[haha @hadoop102 opt]$ mysql -uroot -p Enter password: 输入临时生成的密码10)必须先修改root用户的密码,否则执行其他的操作会报错
mysql> set password = password("123456");11)修改mysql库下的user表中的root用户允许任意ip连接
mysql> update mysql.user set host='%' where user='root'; mysql> flush privileges;