单实例的启动:
1、/etc/init.d/mysqld start 常规启动
ss -lnt|grep 3306 查看端口
ps -ef|grep mysql|grep -v grep 查看进程
2、/mysqld_safe --user=mysql & 初始化数据库时给出的方法
2种方法启动实质是一样的。第2种常用来写脚本。
单实例的关闭:
/etc/init.d/mysqld stop 原理是调用kill mysql_pid,详见mysqld脚本文件。
mysqladmin -uroot -p111 shutdown
强制关闭:
killall mysqld
pkill mysqld
kill -9 mysqld
野蛮粗鲁杀死数据库导致故障企业案例:
http://oldboy.blog.51cto.com/2561410/1421161
多实例启动:
/data/3306/mysql start mysqld_safe --defaults-fie=/data/3307/my.cnf &
多实例关闭:
/data/3307/mysql stop mysqladmin -uroot -p111 -S /data/3307/mysql.sock shutdown
/data/3306/mysql 脚本文件:
#!/bin/sh ################################################ #this scripts is created by oldboy at 2007-06-09 #oldboy QQ:31333741 #site:http://www.etiantian.org #blog:http://oldboy.blog.51cto.com #oldboy trainning QQ group: 208160987 226199307 44246017 ################################################ #init port=3306 mysql_user="root" mysql_pwd="oldboy" CmdPath="/application/mysql/bin" mysql_sock="/data/${port}/mysql.sock" #startup function function_start_mysql() { if [ ! -e "$mysql_sock" ];then printf "Starting MySQL... " /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null & else printf "MySQL is running... " exit fi } #stop function function_stop_mysql() { if [ ! -e "$mysql_sock" ];then printf "MySQL is stopped... " exit else printf "Stoping MySQL... " ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown fi } #restart function function_restart_mysql() { printf "Restarting MySQL... " function_stop_mysql sleep 2 function_start_mysql } case $1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: /data/${port}/mysql {start|stop|restart} " esac