Linux下安装mysql-5.7.30详细步骤
前言
下面记录了我在Linux环境下安装Mysql的完整过程,实操记录,只为让更多人少踩坑,本次安装版本为:mysql-5.7.30,64位操作系统
官网下载地址:mysql-5.7.30-el7-x86_64.tar.gz
百度网盘地址:百度网盘地址 提取码:lyqh
1、安装前准备
检测系统是否自带mysql
[root@localhost /]# rpm -qa | grep mysql
如果是,则使用下面命令进行删除:
[root@localhost /]# rpm -e --nodeps ‘上一步查找的名称’
删除成功后,查询所有Mysql对应的文件夹
[root@localhost ~]# whereis mysql mysql: /usr/bin/mysql /usr/local/mysql [root@localhost ~]# find / -name mysql /run/lock/subsys/mysql /etc/rc.d/init.d/mysql /usr/bin/mysql /usr/local/mysql /usr/local/mysql/bin/mysql /usr/local/mysql/include/mysql /usr/local/mysql/data/mysql
删除上面查找的所有文件夹
2、安装
使用rz命令上传下载好的jar包
[root@localhost ~]# cd /usr/local/ [root@localhost local]# rz
解压
[root@localhost local]# tar -zxvf mysql-5.7.30-el7-x86_64.tar.gz
修改解压目录名称
[root@localhost local]# mv mysql-5.7.30-el7-x86_64/ mysql
在/usr/local/mysql目录下创建data目录
[root@localhost local]# mkdir mysql/data
检查mysql用户组和用户是否存在,如果没有,则创建
[root@localhost local]# cat /etc/group | grep mysql [root@localhost local]# cat /etc/passwd | grep mysql [root@localhost local]# groupadd mysql [root@localhost local]# useradd -r -g mysql mysql
更改mysql目录下所属的用户组和用户,以及权限
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/ [root@localhost local]# chmod -R 755 /usr/local/mysql
编译安装并初始化mysql
[root@localhost local]# cd mysql/bin/ [root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql/
8. 查看并安装libaio包
[root@localhost bin]# rmp -qa|grep libaio -bash: rmp: command not found [root@localhost bin]# yum -y install libaio-devel.x86_64
9.再次执行步骤7,并记住日志最后的初始化密码(记住)
10.编辑配置文件my.cnf
[root@localhost bin]# vi /etc/my.cnf
添加配置如下
[mysqld] datadir=/usr/local/mysql/data port=3306 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/usr/local/mysql/data/mysql.log pid-file=/usr/local/mysql/data/mysql.pid
11.启动mysql服务器
[root@localhost bin]# /usr/local/mysql/support-files/mysql.server start
13. 添加软连接,并重启mysql服务
[root@localhost bin]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql [root@localhost bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql [root@localhost bin]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
14.登录mysql,修改密码为123456(登录的密码是步骤9中初始化密码)
[root@localhost bin]# mysql -u root -p Enter password: mysql>set password for root@localhost = password('123456');
15.开放远程连接
mysql>use mysql; msyql>update user set user.Host='%' where user.User='root'; mysql>flush privileges;
3、测试
1.关闭Linux防火墙
[root@localhost bin]# systemctl stop firewalld.service
2.Navicat连接测试
结束语
如果本篇对您有帮助,请点个赞再加个关注,您的点赞是博主前进的动力!
本篇详细的介绍了mysql-5.7.30的详细安装步骤,为mysql的主从复制教程提供了基础。
感兴趣的同学可以看看博主下一篇linux下搭建mysql主从复制。
————————————————
版权声明:本文为CSDN博主「夏夜凉月的博客」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cool_summer_moon/article/details/106090136