使用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 "^$|^[#;]