MYSQL的启动与关闭

 

1. 关闭数据库命令:
使用MYSQLADMIN的方式关闭数据库
mysqladmin -uroot -p shutdown
查看关库日志:
140608 21:12:21 [Note] /usr/local/mysql/bin/mysqld: Normal shutdown   #正常关闭方式

140608 21:12:21 [Note] Event Scheduler: Purging the queue. 0 events   #清除EVENT队列
140608 21:12:23 [Warning] /usr/local/mysql/bin/mysqld: Forcing close of thread 1011  user: 'root'  #关闭ROOT用户的连接

140608 21:12:23  InnoDB: Starting shutdown...   #开始关闭数据库
140608 21:12:24  InnoDB: Shutdown completed; log sequence number 1613397    #关闭完成,并记录下LSN号
140608 21:12:24 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete       #关闭结束

140608 21:12:24 mysqld_safe mysqld from pid file /data/mysql/mysql_3306/data/mysql_source.pid ended  #结束MYSQL进程。


2. 打开数据库的命令:
cd /usr/local/mysql/bin/
./mysqld_safe --defaults-file=/etc/my.cnf &
查看数据库输出日志:
140608 21:24:54 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data  #开始启动数据库,从定制的数据文件目录。
140608 21:24:54 InnoDB: Mutexes and rw_locks use GCC atomic builtins  #加截MUTEXES AND RW_LOCKS
140608 21:24:54 InnoDB: Compressed tables use zlib 1.2.3  
140608 21:24:54 InnoDB: Using Linux native AIO   
140608 21:24:54 InnoDB: Initializing buffer pool, size = 128.0M  #初始化BUFFER POOL
140608 21:24:54 InnoDB: Completed initialization of buffer pool  #完成初始化
140608 21:24:54 InnoDB: highest supported file format is Barracuda.
140608 21:24:54  InnoDB: Waiting for the background threads to start  #等待启动后台线程。
140608 21:24:55 InnoDB: 5.5.37 started; log sequence number 1613397   #从这里可以看出和上面关机的LSN是一致的。
140608 21:24:55 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306   #绑定IP地址与端口
140608 21:24:55 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
140608 21:24:55 [Note] Server socket created on IP: '0.0.0.0'.  #创建SOCKET
140608 21:24:55 [Note] Event Scheduler: Loaded 0 events   #加载EVENT。
140608 21:24:55 [Note] /usr/local/mysql/bin/mysqld: ready for connections.  #MYSQLD进程等待连接
Version: '5.5.37-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution

3. 导常关库的办法:
kill -9 msyql_pid
这种方法不推荐,并非正常的关机方法, 如果启动是用MYSQLD_SAFE启动的话,KILL是会自动重启的。
[root@mysql_source bin]# kill -9 8844
[root@mysql_source bin]# ./mysqld_safe: line 165:  8844 已杀死               nohup /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/mysql_3306/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql/mysql_3306/data/error.log --open-files-limit=8192 --pid-file=/data/mysql/mysql_3306/data/mysql_source.pid --socket=/tmp/mysql.sock --port=3306 < /dev/null >> /data/mysql/mysql_3306/data/error.log 2>&1
140608 21:44:09 mysqld_safe Number of processes running now: 0
140608 21:44:09 mysqld_safe mysqld restarted

下面写个小脚本用来重启吧。 
#!/bin/sh



MYSQL_BASE=/usr/local/mysql

export PATH=$MYSQL_BASE/bin:/usr/sbin:/usr/bin:/sbin:/bin
export LD_LIBRARY_PATH=$MYSQL_BASE/lib


if [ "$1" = "stop" ] ; then
   $MYSQL_BASE/bin/mysqladmin --defaults-file=/etc/my.cnf -uroot -p shutdown

elif [ "$1" = "restart" ]; then
   $MYSQL_BASE/bin/mysqladmin  --defaults-file=/etc/my.cnf -uroot -p shutdown
   $MYSQL_BASE/bin/mysqld_safe --defaults-file=/etc/my.cnf &
elif [ "$1" = "start" ]; then
   $MYSQL_BASE/bin/mysqld_safe --defaults-file=/etc/my.cnf &

else
        echo "usage: $0 start|stop|restart"
fi

测试脚本:
[root@mysql_source ~]# ./mysql.sh stop
Enter password: 
140608 21:49:36 mysqld_safe mysqld from pid file /data/mysql/mysql_3306/data/mysql_source.pid ended
[1]+  Done                    ./mysqld_safe --defaults-file=/etc/my.cnf  (wd: /usr/local/mysql/bin)
(wd now: ~)
[root@mysql_source ~]# ./mysql.sh start
[root@mysql_source ~]# 140608 21:49:46 mysqld_safe Logging to '/data/mysql/mysql_3306/data/error.log'.
140608 21:49:46 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data

[root@mysql_source ~]# 
[root@mysql_source ~]# 
[root@mysql_source ~]# 
[root@mysql_source ~]# ./mysql.sh restart
Enter password: 
140608 21:50:01 mysqld_safe mysqld from pid file /data/mysql/mysql_3306/data/mysql_source.pid ended
[root@mysql_source ~]# 140608 21:50:02 mysqld_safe Logging to '/data/mysql/mysql_3306/data/error.log'.
140608 21:50:02 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data

  

 

posted @ 2014-06-08 23:31  SMALL-D  阅读(1483)  评论(0编辑  收藏  举报