博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL start and stop
阅读量:5977 次
发布时间:2019-06-20

本文共 12811 字,大约阅读时间需要 42 分钟。

一、本文说明

本实验主要是演示MySQL的四种启动方式,附带停止的操作。

二、mysqld

  mysqld is the MySQL server   mysqld reads options from the [mysqld] and [server] groups   we can invoke mysqld manually.This is usually not done except for debugging purposes.If you invoke the server this way,error messages go to the terminal by default rather than to the error log.

  connection

    start      

       ./bin/mysqld --defaults-file=./my.cnf --user=mysql    

    connect      

        mysql --defaults-file=./my.cnf      

        mysql -S /tmp/mysql.sock

----启动:      [root@node4 mysql5.5]# ./bin/mysqld --defaults-file=./my.cnf --user=mysql &[1] 11315[root@node4 mysql5.5]# 130729  0:50:34 InnoDB: The InnoDB memory heap is disabled130729  0:50:34 InnoDB: Mutexes and rw_locks use InnoDB's own implementation130729  0:50:34 InnoDB: Compressed tables use zlib 1.2.3130729  0:50:34 InnoDB: Initializing buffer pool, size = 128.0M130729  0:50:34 InnoDB: Completed initialization of buffer pool130729  0:50:34 InnoDB: highest supported file format is Barracuda.130729  0:50:34  InnoDB: Waiting for the background threads to start130729  0:50:35 InnoDB: 1.1.8 started; log sequence number 1595675130729  0:50:36 [Note] Event Scheduler: Loaded 0 events130729  0:50:36 [Note] ./bin/mysqld: ready for connections.Version: '5.5.22-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution[root@node4 mysql5.5]# ps -ef |grep mysql |grep -v grepmysql    11315  5333  1 00:50 pts/1    00:00:00 ./bin/mysqld --defaults-file=./my.cnf --user=mysql----连接:[root@node4 mysql5.5]# mysql --defaults-file=./my.cnf[root@node4 mysql5.5]# mysql -S /tmp/mysql.sock ----关闭:[root@node4 mysql5.5]# mysqladmin shutdown

三、mysqld_safe

  mysqld_safe reads all options the [mysqld],[server],and [mysqld_safe] sections in option files.For backward compatibility,it also reads [safe_mysqld] sections,although you should rename such sections to [mysqd_safe] in MySQL 5.1 installations.   mysqld_safe is a shell script that invokes mysqld.The script sets up the error log,and then launches mysqld and monitors it.If mysqld terminates abnormally,mysqld_safe restarts it.

  connection    

     start      

        mysqld_safe --defaults-file=./my.cnf --user=mysql &    

     connect      

        mysql --defaults-file=./my.cnf      

        mysql -S /tmp/mysql.sock

----启动:[root@node4 mysql5.5]# ./bin/mysqld_safe --default-file=./my.cnf --user=mysql &[1] 11352[root@node4 mysql5.5]# 130729 00:54:22 mysqld_safe Logging to '/opt/mysql5.5/data/node4.err'.130729 00:54:23 mysqld_safe Starting mysqld daemon with databases from /opt/mysql5.5/data130729 00:54:25 mysqld_safe mysqld from pid file /opt/mysql5.5/data/node4.pid ended[1]+  Done                    ./bin/mysqld_safe --default-file=./my.cnf --user=mysql----连接:      [root@node4 mysql5.5]# mysql --defaults-file=./my.cnf[root@node4 mysql5.5]# mysql -S /tmp/mysql.sock  ----关闭:[root@node4 mysql5.5]# mysqladmin shutdown

四、mysql.server

  MySQL distributions on Unix include a script named mysql.server.It can be used on
systems such as Linux and Solaris that use System V-style run directaries to start and stop
system services.It is also used by the Max OS X Startup Item for MySQL.
  $MySQL_BASE/share/mysql/mysql.server and support-files/mysql.server
  mysql.server reads options from the [mysql.server] and [mysqld] sections of option files.
For backward compatibility,it also reads [mysql_server] sections,although you should rename
such sections to [mysql.server] when using MySQL 5.1
  a shell script that invoke mysqld_safe. 
 
  connection
    start
      cd share/mysql
       ./mysql.server start
      cp ./mysql.server /etc/rc.d/init.d/mysql
       chkconfig --add mysql
       service mysql start
    connect
      mysql --default-file=./my.cnf
      mysql -S /tmp/mysql.sock

----启动:[root@node4 mysql5.5]# ./support-files/mysql.server startStarting MySQL...                                          [  OK  ][root@node4 mysql5.5]# ps -ef |grep mysql |grep -v greproot     11873     1  1 01:01 pts/1    00:00:00 /bin/sh /opt/mysql5.5/bin/mysqld_safe --datadir=/opt/mysql5.5/data --pid-file=/opt/mysql5.5/data/node4.pidmysql    12329 11873  4 01:01 pts/1    00:00:00 /opt/mysql5.5/bin/mysqld --basedir=/opt/mysql5.5 --datadir=/opt/mysql5.5/data --plugin-dir=/opt/mysql5.5/lib/plugin --user=mysql --log-error=/opt/mysql5.5/data/node4.err --pid-file=/opt/mysql5.5/data/node4.pid --socket=/tmp/mysql.sock --port=3306----设置随系统启动而启动MySQL[root@node4 mysql5.5]# cp ./support-files/mysql.server /etc/init.d/mysql[root@node4 mysql5.5]# chkconfig --add mysql[root@node4 mysql5.5]# chkconfig --list mysqlmysql              0:off    1:off    2:on    3:on    4:on    5:on    6:off[root@node4 mysql5.5]# service mysql startStarting MySQL..                                           [  OK  ][root@node4 mysql5.5]# ps -ef |grep mysql |grep -v greproot     12423     1  1 01:03 pts/1    00:00:00 /bin/sh /opt/mysql5.5/bin/mysqld_safe --datadir=/opt/mysql5.5/data --pid-file=/opt/mysql5.5/data/node4.pidmysql    12881 12423  3 01:03 pts/1    00:00:00 /opt/mysql5.5/bin/mysqld --basedir=/opt/mysql5.5 --datadir=/opt/mysql5.5/data --plugin-dir=/opt/mysql5.5/lib/plugin --user=mysql --log-error=/opt/mysql5.5/data/node4.err --pid-file=/opt/mysql5.5/data/node4.pid --socket=/tmp/mysql.sock --port=3306      ---连接:      [root@node4 mysql5.5]# mysql --defaults-file=./my.cnf[root@node4 mysql5.5]# mysql -S /tmp/mysql.sock  ----关闭:[root@node4 mysql5.5]# mysqladmin shutdown            [root@node4 mysql5.5]# service mysql stopShutting down MySQL.                                       [  OK  ]

五、mysqld_multi

  mysqld_multi is designed to manage several mysqld processes that listen for connections on different Unix socket files and TCP/IP prots.It can start or stop servers,or report their current status.The MySQL Instance Manager is an alternative means of managing multiple servers

  how to config    

    1). mkdir $MySQL_BASE/data2    

    2). mysql_install_db --basedir=$mysql_base              --datadir=$mysql_base/data2              --user=mysql    

    3). vi $MySQL_BASE/my.cnf        

         [mysqld_multi]        

         mysqld = /opt/mysql5152/bin/mysqld_safe        

         mysqladmin = /opt/mysql5152/bin/mysqladmin        

         user = test        

         password = test        

         [mysqld3306]         

           .         

           .         

           .     

      4). mysqld_multi --defaults-file=./my.cnf start 3306     

      5). mysql -uroot -P 3306 --protocol=tcp         

           mysql -S /tmp/mysql3306.sock     

       6). GRANT SHUTDOWN ON *.* TO IDENTIFIED BY 'test';     

       7). mysqld_multi --defaults-file=./my.cnf stop 3306     

 

----创建存放数据库的目录     [root@node4 mysql5.5]# mkdir data2----创建数据库基表[root@node4 mysql5.5]# ./scripts/mysql_install_db --basedir=/opt/mysql5.5 --datadir=/opt/mysql5.5/data2 --user=mysqlInstalling MySQL system tables...130729  1:35:52 [Warning] You need to use --log-bin to make --binlog-format work.OKFilling help tables...130729  1:35:52 [Warning] You need to use --log-bin to make --binlog-format work.OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/opt/mysql5.5/bin/mysqladmin -u root password 'new-password'/opt/mysql5.5/bin/mysqladmin -u root -h node4 password 'new-password'Alternatively you can run:/opt/mysql5.5/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /opt/mysql5.5 ; /opt/mysql5.5/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /opt/mysql5.5/mysql-test ; perl mysql-test-run.plPlease report any problems with the /opt/mysql5.5/scripts/mysqlbug script!----修改data2目录的属主[root@node4 mysql5.5]# chown -R mysql:mysql data2/----修改my.conf文件,添加下面的内容[root@node4 mysql5.5]# more my.cnf                [mysqld_multi]mysqld = /opt/mysql5.5/bin/mysqld_safemysqladmin = /opt/mysql5.5/bin/mysqladminuser = testpassword = test# The MySQL server[mysqld3306]port        = 3306socket        = /tmp/mysql3306.sockpid-file        = /tmp/mysql3306.pidskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mbasedir = /opt/mysql5.5datadir = /opt/mysql5.5/datalog-error = /tmp/mysql3306.err[mysqld3307]port            = 3307socket          = /tmp/mysql3307.sockpid-file        = /tmp/mysql3307.pidskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mbasedir = /opt/mysql5.5datadir = /opt/mysql5.5/data2log-error = /tmp/mysql3307.err----启动3306[root@node4 mysql5.5]# ./bin/mysqld_multi --defaults-file=./my.cnf start 3306 &[1] 13184[root@node4 mysql5.5]# ps -ef |grep 3306 |grep -v greproot     13192     1  0 01:52 pts/1    00:00:00 /bin/sh /opt/mysql5.5/bin/mysqld_safe --port=3306 --socket=/tmp/mysql3306.sock --pid-file=/tmp/mysql3306.pid --skip-external-locking --key_buffer_size=16M --max_allowed_packet=1M --table_open_cache=64 --sort_buffer_size=512K --net_buffer_length=8K --read_buffer_size=256K --read_rnd_buffer_size=512K --myisam_sort_buffer_size=8M --basedir=/opt/mysql5.5 --datadir=/opt/mysql5.5/data --log-error=/tmp/mysql3306.errmysql    13637 13192  1 01:52 pts/1    00:00:00 /opt/mysql5.5/bin/mysqld --basedir=/opt/mysql5.5 --datadir=/opt/mysql5.5/data --plugin-dir=/opt/mysql5.5/lib/plugin --user=mysql --skip-external-locking --key-buffer-size=16M --max-allowed-packet=1M --table-open-cache=64 --sort-buffer-size=512K --net-buffer-length=8K --read-buffer-size=256K --read-rnd-buffer-size=512K --myisam-sort-buffer-size=8M --log-error=/tmp/mysql3306.err --pid-file=/tmp/mysql3306.pid --socket=/tmp/mysql3306.sock --port=3306[1]+  Done                    ./bin/mysqld_multi --defaults-file=./my.cnf start 3306----启动3307[root@node4 mysql5.5]# ./bin/mysqld_multi --defaults-file=./my.cnf start 3307 &[1] 13658[root@node4 mysql5.5]# ps -ef |grep 3307 |grep -v greproot     13666     1  1 01:53 pts/1    00:00:00 /bin/sh /opt/mysql5.5/bin/mysqld_safe --port=3307 --socket=/tmp/mysql3307.sock --pid-file=/tmp/mysql3307.pid --skip-external-locking --key_buffer_size=16M --max_allowed_packet=1M --table_open_cache=64 --sort_buffer_size=512K --net_buffer_length=8K --read_buffer_size=256K --read_rnd_buffer_size=512K --myisam_sort_buffer_size=8M --basedir=/opt/mysql5.5 --datadir=/opt/mysql5.5/data2 --log-error=/tmp/mysql3307.err --log-bin=mysql-bin --binlog_format=mixed --server-id=1mysql    14156 13666 11 01:53 pts/1    00:00:00 /opt/mysql5.5/bin/mysqld --basedir=/opt/mysql5.5 --datadir=/opt/mysql5.5/data2 --plugin-dir=/opt/mysql5.5/lib/plugin --user=mysql --skip-external-locking --key-buffer-size=16M --max-allowed-packet=1M --table-open-cache=64 --sort-buffer-size=512K --net-buffer-length=8K --read-buffer-size=256K --read-rnd-buffer-size=512K --myisam-sort-buffer-size=8M --log-bin=mysql-bin --binlog-format=mixed --server-id=1 --log-error=/tmp/mysql3307.err --pid-file=/tmp/mysql3307.pid --socket=/tmp/mysql3307.sock --port=3307[1]+  Done                    ./bin/mysqld_multi --defaults-file=./my.cnf start 3307----对数据库的连接[root@node4 mysql5.5]# mysql -S /tmp/mysql3306.sockWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.22 Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exit;Bye[root@node4 mysql5.5]# mysql -S /tmp/mysql3307.sockWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.22-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exit;Bye----关闭3306,首先需要连接数据库,创建test用户并授予它权限,最后使用mysqld_multi关闭3306[root@node4 mysql5.5]# mysql -S /tmp/mysql3306.sockWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.22 Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> GRANT SHUTDOWN ON *.* TO 'test'@'localhost' identified by 'test' with grant option;Query OK, 0 rows affected (0.11 sec)mysql> exit;Bye[root@node4 mysql5.5]# ./bin/mysqld_multi --defaults-file=./my.cnf stop 3306[root@node4 mysql5.5]# ps -ef |grep 3306 |grep -v grep

 

 

                               

转载地址:http://vhsox.baihongyu.com/

你可能感兴趣的文章
同事反馈环:为什么度量和会议还不够充分
查看>>
[转]十问 Linux 虚拟内存管理 (glibc)
查看>>
老司机带你深入浅出 Collection
查看>>
JavaScript属性操作
查看>>
查询系统-vba
查看>>
[译]Spring Session 与 Spring Security
查看>>
python学习笔记(05)
查看>>
路由器NAT网络地址转换
查看>>
checkbox全选,全不选
查看>>
7、文档元素
查看>>
linux下的连接文件——软连接和硬连接的区别
查看>>
怎么查看linux文件夹下有多少个文件(mac同样)
查看>>
cacti监控一览无余
查看>>
第十六章--访问文件
查看>>
ASP.NET MVC学前篇之Ninject的初步了解
查看>>
对缓存击穿的一点思考
查看>>
SQL提高及优化
查看>>
Python自动化开发学习15-css补充内容
查看>>
解析find用法
查看>>
JAVA BIO 服务器与客户端实现示例
查看>>