Linux Centos7安装mysql5.7详细教程【tar包安装】

一、准备工作

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! 

. 为了在任何目录下可以登录mysql

ln -s /usr/local/mysql57/bin/mysql /usr/bin/mysql

参考了;(105条消息) Linux Centos7安装mysql5.7详细教程【tar包安装】_铁汉柔情li的博客-CSDN博客

 (105条消息) Linux系统centos7安装mysql5.7教程_安靜のApollo的博客-CSDN博客

(105条消息) 重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor_zhen24的博客-CSDN博客

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值