Linux 7下MySQL自启动配置(glibc)

简介:
+关注继续查看

使用glibc编译后的mysql二进制安装方法被广泛使用,因为它和Windows下的zip方式一下,简单几个步骤,配置一下环境即可。而在Linux 7版本中,MySQL的自启动,不再建议将启动脚本存放到/etc/init.d目录中,因此,我们需要手动配置一下基于systemd方式的自启动文件。下文供大家参考。

一、当前环境

# more /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

安装位置(glibc解压)
# cd /usr/local/mysql/
# ls
bin COPYING data docs include lib man my.cnf README share support-files

二、配置mysql systemd服务

Systemd是一个系统管理守护进程、工具和库的集合,用于取代System V初始进程。
Systemd的功能是用于集中管理和配置类UNIX系统。
在Linux 7版本中,依旧兼容将启动脚本放到/etc/init.d,但不建议这么做。

由于系统存在基于yum方式安装的mysql,因此可以直接复制重命名后修改mysqld.service
# cp /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/mysqld_glibc.service
# vim /usr/lib/systemd/system/mysqld_glibc.service

修改后的对比
# diff /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/mysqld_glibc.service
35c35
< PIDFile=/var/run/mysqld/mysqld.pid
---
> PIDFile=/var/run/mysqld/mysqld_glibc.pid
47c47
< ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS
---
> ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld_glibc.pid $MYSQLD_OPTS

my.cnf的配置
# more /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
pid-file=/var/run/mysqld/mysqld_glibc.pid

启动mysqld_glibc服务
# systemctl start mysqld_glibc.service 
# ps -ef|grep mysql
mysql 7590 1 23 11:12 ? 00:00:00 /usr/local/mysql/bin/mysqld \
  --daemonize --pid-file=/var/run/mysqld/mysqld_glibc.pid

开启自启动
# systemctl enable mysqld_glibc.service

# mysql -uroot -p -S /tmp/mysql.sock
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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>

三、完整的mysqld.service

[root@centos7 ~]# grep -Ev "^$|^[#;]" /usr/lib/systemd/system/mysqld_glibc.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/var/run/mysqld/mysqld_glibc.pid
TimeoutSec=0
PermissionsStartOnly=true
ExecStartPre=/usr/bin/mysqld_pre_systemd
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld_glibc.pid $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
Linux 开发工具
Linux设置服务自启动
Linux设置服务自启动
86 0
|
8月前
|
Linux C语言
LINUX下载编译libc(glibc)
LINUX下载编译libc(glibc)
199 0
|
9月前
|
小程序 Linux 程序员
如何配置frp到linux服务器和windows本地,服务端支持自启动
如何配置frp到linux服务器和windows本地,服务端支持自启动
369 0
如何配置frp到linux服务器和windows本地,服务端支持自启动
|
Linux C语言
Linux入门教程:centos升级glibc至2.18,
官方的glibc源只更新到2.12版,很多业务需要升级到更高级版,这里介绍编译glibc升级的方式。
2864 0
|
MySQL 关系型数据库 Linux
Linux(RHEL7及CentOS7)下glibc版MySQL5.7.20的安装
一、安装环境 操作系统:CentOS Linux release 7.4.1708 (Core)  MySQL:mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 二、下载、安装、配置过程 1、创建安装MySQL的用户geeklp,并指定用户目录。
1804 0
推荐文章
更多