阿里云linux 重启mysql_linux自动启动mysql的方法

dc25a6aed567a1f78fbd189afc43525a.png

836014053883d7f6fd843fd3d43fd22c.png

最简单的方法,直接编辑/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值