Centos7.9安装mysql 5.7,并设置开机启动

22 篇文章 0 订阅
1 篇文章 0 订阅

目录

1、下载

 2、安装

 3、连接mysql

 4、设置开机启动


1、下载

下载地址:

MySQL :: Download MySQL Community Serverhttps://dev.mysql.com/downloads/mysql/5.7.html

 

 或者在这里下载:

mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz-Java文档类资源-CSDN下载mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz官网上下载更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/fyihdg/85605607

下载后,上传到服务器:

 2、安装

检查是否安装过mysql

rpm -qa|grep mysql

 没有安装过

查看系统自带的Mariadb

rpm -qa|grep mariadb

卸载系统自带的Mariadb

创建mysql 用户组和用户

groupadd mysql
useradd -r -g mysql mysql

 执行命令:

tar -xvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz  -C /opt

 切换到/ope目录

修改名称

 mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql5.7

 修改权限,用户组

chown -R mysql:mysql /opt/mysql5.7
chmod -R 755 /opt/mysql5.7

 进入:/opt/mysql5.7/bin,执行

./mysqld --initialize --user=mysql --datadir=/opt/mysql5.7/data --basedir=/opt/mysql5.7

新建文件:

vi /etc/my.cnf

写入以下内容:

[mysqld]
datadir=/opt/mysql5.7/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1

授权

chmod -R 775 /etc/my.cnf

修改文件:

 vi /opt/mysql5.7/support-files/mysql.server 

 

 启动服务:

/opt/mysql5.7/support-files/mysql.server start

 root      23261  21419  0 22:01 pts/0    00:00:00 grep --color=auto mysqld
[root@node05 support-files]# /opt/mysql5.7/support-files/mysql.server start
my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Starting MySQL.my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Logging to '/opt/mysql5.7/data/node05.err'.
 ERROR! The server quit without updating PID file (/opt/mysql5.7/data/node05.pid).

报错了,原因有

1、数据目录mysql用户没有权限

2、/etc/my.cnf配置文件配置有错,[mysqld]下设置这一行:datadir = /opt/mysql/data

3、还有就是/etc/格式问题my.cnf

检查启动成功后:

添加软连接,并重启mysql 服务

ln -s /opt/mysql5.7/support-files/mysql.server /etc/init.d/mysql

ln -s /opt/mysql5.7/bin/mysql /usr/bin/mysql
service mysql restart

 3、连接mysql

 用户名是:root,密码是刚才安装过程中生成的密码

 修改root密码:

set password for root@localhost = password('root');

开放远程连接


 

use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;

 

 

 4、设置开机启动

执行以下命令

//将服务文件拷贝到init.d下,并重命名为mysql
cp /opt/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
//赋予可执行权限
chmod +x /etc/init.d/mysqld
//添加服务
chkconfig --add mysqld
//显示服务列表
chkconfig --list

 如果不通,关闭防火墙:

#开启防火墙
systemctl start firewalld

#关闭防火墙
systemctl stop firewalld

或者

//开放3306端口命令
firewall-cmd --zone=public --add-port=3306/tcp --permanent
//配置立即生效
firewall-cmd --reload

至此,安装成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fyihdg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值