mysql几种启动和关闭mysql服务的方法和区别

mysql⼏种启动关闭mysql服务的⽅法和区别
mysql⼏种启动⽅法
⽅法1、mysqld
a7105mysqld指定读取myf配置⽂件启动,加⼀个 & 实现后台启动。终端不会被阻塞
./mysqld --defaults-file=/etc/myf &
⽅法2、mysqld_safe
./mysqld_safe –defaults-file=/etc/myf  &
⽅法3、mysql.server
将support-files/mysql.server 脚本做成⼀个linux服务。使⽤服务的⽅式启动
cp -v /usr/local/mysql/support-files/mysql.server /etc/init.d/
chkconfig –add mysql.server
service mysql.server {start|stop|restart|reload|force-reload|status}
⽅法4、./etc/init.d/mysqld start
这种⽅式其实和support-files⼀样。不过更清晰点,我⽐较喜欢⽤这个。
⽅法5、mysqld_multi
mysqld_multi 主要⽤来多实例启动的。见
mysqld和mysqld_safe启动有什么区别?
1、使⽤file命令分别查看mysqld和mysqld_safe两个执⾏⽂件。可见
mysqld是⼀个64位的 dynamically linked ;
mysqld_safe 是⼀个shell script;shell脚本。可以直接编辑的。
[root@localhost bin]# file mysqld
mysqld: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, BuildID[sha1]=e1d1f6fd34afae9ac33181c12d605976c81cc6e1, not stripped
[root@localhost bin]# file mysqld_safe
mysqld_safe: POSIX shell script, ASCII text executable
灶神之妻2、使⽤ps-ef查看下⼆者区别
mysqld
[root@localhost bin]# ps -ef |grep mysql
mysql      929483641211:12 pts/200:00:00 ./mysqld --defaults-file=/etc/myf
mysqld_safe
[root@localhost ~]# ps -ef |grep mysql
root      93998364011:13 pts/200:00:00/bin/sh ./mysqld_safe --defaults-file=/etc/myf
mysql      95559399211:13 pts/200:00:00/home/mysql5.7/mysql-5.7.33-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/etc/myf --basedir=/home/mysql5.7/mysql-5.7.33-linux-glibc2.12-x86_64 --datadir=/mdata/mysql57 --plugin-dir=/ho mysqld_safe命令启动的⽅式要⽐mysqld启动多了
⼀个mysqld_safe的进程;mysqld_safe 其实就是mysqld服务的⼀个守护进程;它的作⽤是当mysql宕机后会⾃动重启mysqld服务。所以平时应该使⽤mysqld_safe。
如下我⼿动kill掉9555这个mysql进程,随后再次执⾏ps -ef |grep mysql 发现⼜⽣成了⼀个pid为9918 的mysql进程。
[root@localhost ~]# kill-99555
[root@localhost ~]# ps -ef |grep mysql
root      93998364011:13 pts/200:00:00/bin/sh ./mysqld_safe --defaults-file=/etc/myf
mysql      99189399811:19 pts/200:00:00/home/mysql5.7/mysql-5.7.33-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/etc/myf --basedir=/home/mysql5.7/mysql-5.7.33-linux-glibc2.12-x86_64 --datadir=/mdata/mysql57 --plugin-dir=/ho root      99508476011:19 pts/300:00:00 grep --color=auto mysql昭阳e255
mysql⼏种关闭⽅法
mysql终端使⽤,需要密码
⽅法1、进⼊mysql终端执⾏shutdown命令可以关闭mysql服务
[root@localhost bin]# mysql -S /tmp/mysql.sock3305 -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is3
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
(root@localhost) [(none)]>shutdown;
Query OK, 0 rows affected (0.00 sec)
(root@localhost) [(none)]>show variables like'%port%';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock3305' (2)
ERROR:
Can't connect to the server
(root@not_connected) [(none)]>exit;
Bye
[root@localhost bin]#
mysql终端使⽤,需要密码
⽅法2、在mysql终端关闭mysql的另⼀种命令:
mysqladmin可以做到在mysql终端⽆需真正登录进去就可stop mysql server
[root@localhost bin]# ./mysqladmin -uroot -p1111aaA_ -S /tmp/mysql.sock3305 shutdown
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
在部署mysql的服务器上使⽤,不需要密码
⽅法3、./support-files/mysql.server stop
[root@localhost ~]# file/home/mysql5.7/mysql-5.7.33-linux-glibc2.12-x86_64/support-files/mysql.server /home/mysql5.7/mysql-5.7.33-linux-glibc2.12-x86_64/support-files/mysql.server: POSIX shell script, ASCII text executable
mysql.server 是⼀个 shell script。那么我们查看⼀下它:
....
'stop')
# Stop daemon. We use a signal here to avoid having to know the
# root password.
if test -s "$mysqld_pid_file_path"
then
# signal mysqld_safe that it needs to stop
touch "$mysqld_pid_file_path.shutdown"
mysqld_pid=`cat "$mysqld_pid_file_path"`
if (kill-0 $mysqld_pid 2>/dev/null)
then
echo $echo_n "Shutting down MySQL"
kill $mysqld_pid
# mysqld should remove the pid file when it exits, so wait for it.
wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?
else
log_failure_msg "MySQL server process #$mysqld_pid is not running!"
rm "$mysqld_pid_file_path"
fi
河南厕所革命# Delete lock for RedHat / SuSE
if test -f "$lock_file_path"
then
青岛开发区人事局rm -f "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "MySQL server PID file could not be found!"
fi
;;
<
可见,mysql.server stop使⽤kill -0 pid 来实现关闭的。
利⽤了linux中的⼀个信号机制。kill -9 表⽰强制关闭。若使⽤的是kill -0 表⽰发⽣⼀个信号给进程,若应⽤程序中有负责接收处理信号的话,就会⾛正常关闭的代码流程。故linux的kill -0 命令在mysql中是⼀个正常的安全关闭。可以做请使⽤kill -0 pid 来关闭mysql⽽不是kill -9 pid

本文发布于:2024-09-20 20:47:00,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/718920.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:服务   启动   终端   关闭   信号   命令   负责
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议