linux自动启动mysql的方法

linux自动启动mysql的方法http://www.bieryun.com/3225.html

linux自动启动mysql的方法

最简单的方法,直接编辑/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@localhost ~]# ps -ef | grep mysql
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
上一篇:暗渡陈仓:用低消耗设备进行破解和渗透测试1.2.1 运行Deck的设备


下一篇:oracle等待事件10——I/O上的等待事件 下篇