本文共 2603 字,大约阅读时间需要 8 分钟。
手动安装的mysql是不会自动添加到系统服务中的。如果需要配置开机启动,最好是将mysql配置成系统服务,也便于管理。
1、先去mysql安装目录启动mysql
[root@host01 mysql]# cd /usr/local/mysql/support-files/[root@host01 support-files]# pwd/usr/local/mysql/support-files[root@host01 support-files]# ./mysql.server startStarting MySQL. SUCCESS! [root@host01 support-files]#
2、查看mysql进程,找到【–pid-file】对应的值,然后可以停掉mysql
[root@host01 support-files]# ps -ef | grep mysqlroot 5877 1 0 10:32 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/host01.pidmysql 6029 5877 1 10:32 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/host01.pid --socket=/var/lib/mysql/mysql.sockroot 6059 3035 0 10:33 pts/0 00:00:00 grep --color=auto mysql[root@host01 support-files]# [root@host01 support-files]# ./mysql.server stopShutting down MySQL.. SUCCESS! [root@host01 support-files]#
1、在/usr/lib/systemd/system目录下创建【mysql.service】内容如下,注意路径可能有变化,根据实际情况写,PIDFile就是上面拿到的路径文件名
[Unit]Description=MysqlAfter=syslog.target network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/usr/local/mysql/data/host01.pidExecStart=/usr/local/mysql/support-files/mysql.server startExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=false[Install]WantedBy=multi-user.target
2、重启systemctl,让mysql.service生效
[root@host01 support-files]# systemctl daemon-reload
3、测试通过service方式启动mysql
[root@host01 support-files]# ps -ef |grep mysqlroot 6105 3662 0 10:42 pts/2 00:00:00 grep --color=auto mysql[root@host01 support-files]# systemctl start mysql[root@host01 support-files]# ps -ef |grep mysqlroot 6119 1 1 10:42 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/host01.pidmysql 6272 6119 10 10:42 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/host01.pid --socket=/var/lib/mysql/mysql.sockroot 6302 3662 0 10:42 pts/2 00:00:00 grep --color=auto mysql[root@host01 support-files]#
4、mysql服务相关命令
将mysql设置为开机启动systemctl enable mysql将mysql设置为开机不启动systemctl disable mysql启动mysqlsystemctl start mysql关闭mysqlsystemctl stop mysql重启mysqlsystemctl restart mysql
转载地址:http://yulwb.baihongyu.com/