MySQL的启动和停止(5.6.21)
MySQL的启动方式有四种,分别是直接启动mysqld服务,mysql_safe启动方法,直接启动mysql.server服务(/opt/mysql/support-file/),还有就是mysql_multi,下面对这四种分别详细说明
1.mysqld
-
mysqld is 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 the terminal by default rather than to the error log
不知道是5.6.21的版本的问题还是什么原因,在用mysqld启动的时候要把
--defaults-file=../my.cnf
--basedir=/opt/mysql
--datadir=/opt/mysql/data
--plugin-dir=/opt/mysql/lib/plugin
--user=mysql --log-error=/opt/mysql/data/mysql1.err
--pid-file=/opt/mysql/data/mysql1.pid
--socket=/opt/mysql/mysql.sock
--port=3306这些参数全部指定,如果每次在命令中中指定这些参数难免显得非常麻烦,所以我就把这些参数全部写在mysql的配置文件my.cnf中的[mysqld]下面。
connect
./opt/mysql/bin/mysqld --defaults-file=/opt/mysql/my.cnf --user=mysql
mysql --defaults-file=/opt/mysql/my.cnf
mysql -S /tmp/mysql.sock (用socket的方式进行连接)
2.mysqld_safe
-
mysqld_safe reads all options from the [mysqld],[server] and [mysqld_safe] sections in option file .for backward compatibility.it also reads [safe_mysqld] sections.although you should rename such sections to [mysqld_safe] in MYSQL 5.1 installations
-
mysqld_safe is a shell scripts that invokes mysqld.the scripts sets up the error log .and then launches mysqld and monitors it.if msqld terminates abnormally.mysqld_safe restarts it
connection
mysqld_safe --defaults-file=/opt/mysql/my.cnf --user=mysql
mysql --defaults-file=/opt/mysql/my.cnf
mysql -S /tmp/mysql.sock
3.mysql.server
-
MYSQL distributions on unix include a script named mysql.server.it can be used on system such as linux and solaris that use system V-style run directories to start and stop system services.it is also used by the Mac OS X startup Item for mysql
-
$MYSQL_BASE/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 invokes mysqld_safe
connection
cd /opt/mysql/support-files/mysql.server start
也可封装成系统服务:
cp /opt/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
service mysql start
mysql --defaults-file=/opt/mysql/my.cnf
mysql -S /tmp/mysql.sock
4.mysqld_multi
-
mysqld_multi is designed to manage serveral processes that listen for connections on different unix socket and TCP/IP ports. it can start or stop servers,or reprot their current status .the mysql instance manager is an alternative of managing multiple servers
how to config
-
makdir $basedir/data2
-
mysql_install_db --basedir=$basedir --datadir=/basedir/data2 --user=mysql
-
vi /opt/mysql/my.cnf
[mysqld_multi]
mysqld =/opt/mysql/bin/mysqld_safe
mysqladmin =/opt/mysql/bin/mysqladmin
user=test
password=test
[mysqld3306]
.
.
.
[mysqld3307]
.
.
.
-
mysqld_multil --default-file=/opt/mysql/my.cnf start 3306
-
mysql -uroot -p 3306 --protocol=tcp
-
mysql -S /tmp/mysql3306.sock
-
grant shutdown on *.* to 'test'@'localhost' identified by 'test'
-
mysqld_multil --defaults-file=/opt/mysql/cm.cnf stop 3306
下面是一个有三个server的机器上的my.cnf文件:
-
[mysqld_multi]
-
mysqld =/opt/mysql/bin/mysqld_safe
-
mysqladmin =/opt/mysql/bin/mysqladmin
-
user=test
-
password=test
-
-
-
[mysqld3306]
-
-
port = 3306
-
socket = /opt/mysql/mysql.sock
-
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/mysql
-
datadir = /opt/mysql/data
-
-
plugin-dir=/opt/mysql/lib/plugin
-
pid-file=/opt/mysql/data/mysql1.pid
-
log-error=/opt/mysql/data/mysql1.err
-
explicit_defaults_for_timestamp
-
-
[mysqld3307]
-
-
port = 3307
-
socket = /opt/mysql/mysql3307.sock
-
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/mysql
-
datadir = /opt/mysql/data2
-
-
plugin-dir=/opt/mysql/lib/plugin
-
pid-file=/opt/mysql/data2/mysql1.pid
-
log-error=/opt/mysql/data2/mysql1.err
-
explicit_defaults_for_timestamp
-
-
-
[mysqld3308]
-
-
port = 3308
-
socket = /opt/mysql/mysql3308.sock
-
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/mysql
-
datadir = /opt/mysql/data3
-
-
plugin-dir=/opt/mysql/lib/plugin
-
pid-file=/opt/mysql/data3/mysql1.pid
-
log-error=/opt/mysql/data3/mysql1.err
-
explicit_defaults_for_timestamp
-
-
[client]
-
prot =3306
-
socket =/opt/mysql/mysql.sock
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28687558/viewspace-1335073/
,如需转载,请注明出处,否则将追究法律责任。