linux自動啟動mysql的方法
http://www.bieryun.com/3225.html最簡單的方法,直接編輯/etc/rc.local配置檔案
先直接關閉現在啟動的mysqld服務
msyqladmin -uroot -p -S /tmp/mysql.3306.sock shutdown
重新開機機器測試檢視:shutdown -r now
ps -ef | grep mysql
[root@localhost ~]# ps -ef | grep mysql
root 1942 1 0 12:29 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 2026 1942 0 12:29 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 2319 2263 0 12:31 pts/0 00:00:00 grep mysql
這是系統啟動mysql服務的背景程式
于是把這些關掉
chkconfig mysqld off
[root@localhost ~]# chkconfig | grep mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
再重新開機後就ps 就沒查到預設啟動的錯誤mysql程序了。
編輯/etc/rc.local檔案:
[root@localhost ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.3306.cnf --user=mysql &
[root@localhost ~]#
重新開機檢視生效。可以正常登陸:
[c:\~]$ ssh 192.168.125.128
Connecting to 192.168.125.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Tue Apr 3 12:44:28 2018 from 192.168.125.1
root 2095 1 0 12:45 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.3306.cnf --user=mysql
mysql 3309 2095 1 12:46 ? 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.3306.cnf --basedir=/usr/local/mysql --datadir=/database/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/database/3306/data/3306.err --open-files-limit=65000 --pid-file=/database/3306/data/3306.pid --socket=/tmp/mysql_3306.sock --port=3306
root 3416 3396 0 12:46 pts/0 00:00:00 grep mysql
[root@localhost ~]# mysql6
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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> exit
Bye