使用glibc编译后的mysql二进制安装方法被普遍使用,由于它和Windows下的zip方式一下,简单几个步骤,配置一下环境便可。而在Linux 7版本中,MySQL的自启动,再也不建议将启动脚本存放到/etc/init.d目录中,所以,咱们须要手动配置一下基于systemd方式的自启动文件。下文供你们参考。mysql
# 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
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>
[root@centos7 ~]# grep -Ev "^$|^[#;]