mysql啟動的四種方式

小亮520cl發表於2015-01-21
mysql的四種啟動方式:
1、mysqld(現在很少直接用mysqld啟動了,一般用mysqld_safe)
啟動mysql伺服器:./mysqld --defaults-file=/etc/my.cnf --user=mysql
客戶端連線:
mysql --defaults-file=/etc/my.cnf
or
mysql -S /tmp/mysql.sock

2、mysqld_safe
啟動mysql伺服器:./mysqld_safe --defaults-file=/etc/my.cnf --user=mysql&
客戶端連線:
mysql --defaults-file=/etc/my.cnf
or
mysql -S /tm/mysql.sock

3、mysql.server
cp -v /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql   
(rpm安裝之後系統自動幫你cp了,路徑自己去find一下吧)
chkconfig --add mysql   (add需要自己去手動新增)
啟動mysql伺服器:service mysql {start|stop|restart|reload|force-reload|status}
               /etc/init.d/mysql start|stop   
客戶端連線:同1、2

4、mysqld_multi    (管理多個伺服器時候常用的)
mkdir $MYSQL_BASE/data2
cat <> /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /user/local/mysql/bin/mysqladmin
user = mysqladmin
password = mysqladmin

[mysqld3306]
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 = /usr/local/mysql
datadir = /usr/local/mysql/data

[mysqld3307]
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 = /usr/local/mysql
datadir = /usr/local/mysql/data2
EOF

#mysql -S /tmp/mysql3306.sock
mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option;

#mysql -S /tmp/mysql3307.sock
mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option;

啟動mysql伺服器:./mysqld_multi --defaults-file=/etc/my.cnf start|report|stop 3306-3307
關閉mysql伺服器:mysqladmin -uroot -p -P3306 shutdown
               

可參考<>
http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#server-side-scripts

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-1409002/,如需轉載,請註明出處,否則將追究法律責任。

相關文章