一、准备工作
1、下载安装包:下载mysql5.7 oracle地址(使用社区版即可,免费)
2、上传到自己的目录
3、卸载系统自带的Mariadb
[root@hdp265dnsnfs ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@hdp265dnsnfs ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
执行yum remove -y
rpm -qa mariadb*``进行移除
二、安装
#1、解压tar包
tar zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
#修改目录名
mv mysql-5.7.30-linux-glibc2.12-x86_64 mysql
#在mysql下新增data目录和my.cnf配置文件
mkdir data
touch my.cnf
#my.cnf文件里添加一下内容:
[mysqld]
port = 3306
basedir=/opt/soft/mysql
datadir=/opt/soft/mysql/data
socket=/opt/soft/mysql/mysql.sock
user=mysql
symbolic-links=0
log-error=/opt/soft/mysql/error.log
pid-file=/opt/soft/mysql/mysql.pid
#在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程,设置密码后去掉
skip-grant-tables
#新增mysql组和mysql用户,并将mysql文件夹里的用户和组全变成mysql
# 新建组和账号
groupadd mysql
useradd -r -g mysql mysql
# 改变mysql目录下所有文件的组和账号所属
cd mysql
chown -R mysql .
chgrp -R mysql .
# 以上后两句也可以替换
chown mysql:mysql -R .
#进入bin目录执行初始化命令[非常重要]
cd bin
[root@localhost bin]# ./mysqld --defaults-file=/opt/soft/mysql/my.cnf --basedir=/opt/soft/mysql/ --datadir=/opt/soft/mysql/data --user=mysql --initialize
[root@hdp265dnsnfs mysql57]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@hdp265dnsnfs mysql57]# chown 777 /etc/my.cnf
[root@hdp265dnsnfs mysql57]# chmod +x /etc/init.d/mysqld
# 修改下/etc/init.d/mysqld 的
basedir=/opt/soft/mysql
datadir=/opt/soft/mysql/data
三、重启
[root@hdp265dnsnfs mysql57]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
四、设置开机启动
[root@hdp265dnsnfs mysql57]# chkconfig --level 35 mysqld on
[root@hdp265dnsnfs mysql57]# chkconfig --list mysqld
[root@hdp265dnsnfs mysql57]# chmod +x /etc/rc.d/init.d/mysqld
[root@hdp265dnsnfs mysql57]# chkconfig --add mysqld
[root@hdp265dnsnfs mysql57]# chkconfig --list mysqld
[root@hdp265dnsnfs mysql57]# service mysqld status
SUCCESS! MySQL running (4475)
五、设置环境变量etc/profile/
export PATH=$PATH:/opt/soft/mysql57/bin
[root@hdp265dnsnfs mysql57]# source /etc/profile
六、登录
注意:在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程,重启 /etc/init.d/mysqld restart ;
#连接有问题时最简单的办法解决就是,弄个软连接,连接上去就ok了ln -s /opt/soft/mysql/mysql.sock /tmp/mysql.sock
重启之后输入mysql即可进入mysql。
[root@localhost]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> use mysql;
#修改密码
use mysql;
update user set authentication_string=password("你的密码") where user="root";
FLUSH PRIVILEGES;
#编辑my.cnf,去掉刚才添加的内容,然后重启MySQL。大功告成!
#重新登录
set PASSWORD = PASSWORD('你的密码');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
七、重启生效
/bin/systemctl restart mysql.service
[root@hdp265dnsnfs bin]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
ln -s /usr/local/mysql57/bin/mysql /usr/bin/mysql
参考了;(105条消息) Linux Centos7安装mysql5.7详细教程【tar包安装】_铁汉柔情li的博客-CSDN博客