MySQL Server Startup Script
MySQL Server Startup Script
在Unix和類似於Unix的系統中的MySQL釋出版本包含一個名叫mysql.server的指令碼,它將呼叫mysqld_safe來啟動MySQL伺服器。它也可以用於像Linux和Solaris系統上使用System V-style來執行指令來啟動和停止系統服務。也可以被macOS啟動專案來啟動MySQL。
mysql.server是MySQL原始碼樹中的指令碼名稱。其安裝後的名稱可能不一樣,例如,mysqld或mysql。下面將會介紹將mysql.server指令碼調整成適合於你係統的名稱。注意對於某些Linux平臺,使用RPM或Debian包安裝的MySQL包含用來管理MySQL伺服器啟動和關閉的systemd的支援。在這些平臺上,mysql.server和mysqld_safe不需要安裝因為不需要它們。
為了使用mysql.server來手動啟動或停止MySQL服務,可以從命令呼叫它並使用start或stop引數:
[root@localhost support-files]# ./mysql.server stop Shutting down MySQL.. SUCCESS! [root@localhost support-files]# ./mysql.server start Starting MySQL.. SUCCESS!
相關日誌資訊如下:
2019-08-22T13:29:13.429419Z 0 [Note] Giving 0 client threads a chance to die gracefully 2019-08-22T13:29:13.429508Z 0 [Note] Shutting down slave threads 2019-08-22T13:29:13.429535Z 0 [Note] Forcefully disconnecting 0 remaining clients 2019-08-22T13:29:13.429553Z 0 [Note] Event Scheduler: Purging the queue. 0 events 2019-08-22T13:29:13.429630Z 0 [Note] Binlog end 2019-08-22T13:29:13.460102Z 0 [Note] Shutting down plugin 'ngram' 2019-08-22T13:29:13.460187Z 0 [Note] Shutting down plugin 'partition' 2019-08-22T13:29:13.460214Z 0 [Note] Shutting down plugin 'BLACKHOLE' 2019-08-22T13:29:13.460235Z 0 [Note] Shutting down plugin 'ARCHIVE' 2019-08-22T13:29:13.460277Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA' 2019-08-22T13:29:13.460405Z 0 [Note] Shutting down plugin 'MRG_MYISAM' 2019-08-22T13:29:13.460446Z 0 [Note] Shutting down plugin 'MyISAM' 2019-08-22T13:29:13.460553Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL' 2019-08-22T13:29:13.460599Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES' 2019-08-22T13:29:13.460619Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES' 2019-08-22T13:29:13.460637Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS' 2019-08-22T13:29:13.460681Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN' 2019-08-22T13:29:13.460736Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS' 2019-08-22T13:29:13.460776Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS' 2019-08-22T13:29:13.460898Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES' 2019-08-22T13:29:13.460920Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS' 2019-08-22T13:29:13.460938Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES' 2019-08-22T13:29:13.460956Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE' 2019-08-22T13:29:13.460973Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE' 2019-08-22T13:29:13.460991Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG' 2019-08-22T13:29:13.461008Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED' 2019-08-22T13:29:13.461026Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED' 2019-08-22T13:29:13.461044Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD' 2019-08-22T13:29:13.461089Z 0 [Note] Shutting down plugin 'INNODB_METRICS' 2019-08-22T13:29:13.461140Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO' 2019-08-22T13:29:13.461161Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS' 2019-08-22T13:29:13.461180Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU' 2019-08-22T13:29:13.461220Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE' 2019-08-22T13:29:13.461286Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET' 2019-08-22T13:29:13.461306Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX' 2019-08-22T13:29:13.461325Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET' 2019-08-22T13:29:13.461343Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM' 2019-08-22T13:29:13.461361Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET' 2019-08-22T13:29:13.461378Z 0 [Note] Shutting down plugin 'INNODB_CMP' 2019-08-22T13:29:13.461396Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS' 2019-08-22T13:29:13.461414Z 0 [Note] Shutting down plugin 'INNODB_LOCKS' 2019-08-22T13:29:13.461431Z 0 [Note] Shutting down plugin 'INNODB_TRX' 2019-08-22T13:29:13.461450Z 0 [Note] Shutting down plugin 'InnoDB' 2019-08-22T13:29:13.461776Z 0 [Note] InnoDB: FTS optimize thread exiting. 2019-08-22T13:29:13.462092Z 0 [Note] InnoDB: Starting shutdown... 2019-08-22T13:29:13.562479Z 0 [Note] InnoDB: Dumping buffer pool(s) to /mysqldata/mysql/ib_buffer_pool 2019-08-22T13:29:13.563934Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 190822 21:29:13 2019-08-22T13:29:14.807857Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2530229 2019-08-22T13:29:14.810644Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2019-08-22T13:29:14.810690Z 0 [Note] Shutting down plugin 'MEMORY' 2019-08-22T13:29:14.810707Z 0 [Note] Shutting down plugin 'CSV' 2019-08-22T13:29:14.810721Z 0 [Note] Shutting down plugin 'sha256_password' 2019-08-22T13:29:14.810731Z 0 [Note] Shutting down plugin 'mysql_native_password' 2019-08-22T13:29:14.810961Z 0 [Note] Shutting down plugin 'binlog' 2019-08-22T13:29:14.811432Z 0 [Note] /mysqlsoft/mysql/bin/mysqld: Shutdown complete 2019-08-22T13:30:24.969246Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled 2019-08-22T13:30:24.969441Z 0 [Note] /mysqlsoft/mysql/bin/mysqld (mysqld 5.7.26) starting as process 32558 ... 2019-08-22T13:30:24.980591Z 0 [Note] InnoDB: PUNCH HOLE support available 2019-08-22T13:30:24.980678Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2019-08-22T13:30:24.980740Z 0 [Note] InnoDB: Uses event mutexes 2019-08-22T13:30:24.980758Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2019-08-22T13:30:24.980779Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2019-08-22T13:30:24.981460Z 0 [Note] InnoDB: Number of pools: 1 2019-08-22T13:30:24.981799Z 0 [Note] InnoDB: Using CPU crc32 instructions 2019-08-22T13:30:24.985591Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2019-08-22T13:30:25.002296Z 0 [Note] InnoDB: Completed initialization of buffer pool 2019-08-22T13:30:25.007382Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2019-08-22T13:30:25.021394Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2019-08-22T13:30:25.063462Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2019-08-22T13:30:25.063830Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2019-08-22T13:30:25.758116Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2019-08-22T13:30:25.760396Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2019-08-22T13:30:25.760448Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2019-08-22T13:30:25.761681Z 0 [Note] InnoDB: Waiting for purge to start 2019-08-22T13:30:25.811963Z 0 [Note] InnoDB: 5.7.26 started; log sequence number 2530229 2019-08-22T13:30:25.812330Z 0 [Note] InnoDB: Loading buffer pool(s) from /mysqldata/mysql/ib_buffer_pool 2019-08-22T13:30:25.813642Z 0 [Note] Plugin 'FEDERATED' is disabled. 2019-08-22T13:30:25.819058Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190822 21:30:25 2019-08-22T13:30:25.824582Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 2019-08-22T13:30:25.825236Z 0 [Warning] CA certificate ca.pem is self signed. 2019-08-22T13:30:25.827375Z 0 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306 2019-08-22T13:30:25.827463Z 0 [Note] - '0.0.0.0' resolves to '0.0.0.0'; 2019-08-22T13:30:25.829361Z 0 [Note] Server socket created on IP: '0.0.0.0'. 2019-08-22T13:30:25.859593Z 0 [Note] Event Scheduler: Loaded 0 events 2019-08-22T13:30:25.859938Z 0 [Note] /mysqlsoft/mysql/bin/mysqld: ready for connections. Version: '5.7.26' socket: '/mysqlsoft/mysql/mysql.sock' port: 3306 Source distribution
mysql.server進入到MySQL安裝目錄,然後呼叫mysqld_safe。為了讓某些特定的使用者能夠執行服務,在全域性/etc/my.cnf選項檔案中為[mysqld]組增加一個合適的user選項,後面將會介紹(如果你將二進位制版本的MySQL安裝在非標準位置,那麼可能必須要修改mysql.server指令碼。修改它是為了在執行mysqld_safe之前進入到合適的目錄中。如果這樣做,當將來升級MySQL時你修改的mysql.server版本可能會被覆蓋,建立一個你修改版本的副本可以進行重新安裝)。
mysql.server stop透過傳送一個訊號給它來停止MySQL服務。也可以透過執行mysqladmin shutdown來手動關閉服務。
[root@localhost bin]# ./mysqladmin -uroot -p123456 shutdown mysqladmin: [Warning] Using a password on the command line interface can be insecure.
日誌資訊如下:
2019-08-22T13:44:57.170282Z 0 [Note] Giving 0 client threads a chance to die gracefully 2019-08-22T13:44:57.170357Z 0 [Note] Shutting down slave threads 2019-08-22T13:44:57.170919Z 0 [Note] Forcefully disconnecting 0 remaining clients 2019-08-22T13:44:57.171016Z 0 [Note] Event Scheduler: Purging the queue. 0 events 2019-08-22T13:44:57.171140Z 0 [Note] Binlog end 2019-08-22T13:44:57.172096Z 0 [Note] Shutting down plugin 'ngram' 2019-08-22T13:44:57.172142Z 0 [Note] Shutting down plugin 'partition' 2019-08-22T13:44:57.172203Z 0 [Note] Shutting down plugin 'BLACKHOLE' 2019-08-22T13:44:57.172225Z 0 [Note] Shutting down plugin 'ARCHIVE' 2019-08-22T13:44:57.172259Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA' 2019-08-22T13:44:57.172317Z 0 [Note] Shutting down plugin 'MRG_MYISAM' 2019-08-22T13:44:57.172348Z 0 [Note] Shutting down plugin 'MyISAM' 2019-08-22T13:44:57.172398Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL' 2019-08-22T13:44:57.172428Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES' 2019-08-22T13:44:57.172441Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES' 2019-08-22T13:44:57.172452Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS' 2019-08-22T13:44:57.172476Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN' 2019-08-22T13:44:57.172506Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS' 2019-08-22T13:44:57.172564Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS' 2019-08-22T13:44:57.172579Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES' 2019-08-22T13:44:57.172590Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS' 2019-08-22T13:44:57.172601Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES' 2019-08-22T13:44:57.172612Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE' 2019-08-22T13:44:57.172623Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE' 2019-08-22T13:44:57.172634Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG' 2019-08-22T13:44:57.172644Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED' 2019-08-22T13:44:57.172655Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED' 2019-08-22T13:44:57.172666Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD' 2019-08-22T13:44:57.172676Z 0 [Note] Shutting down plugin 'INNODB_METRICS' 2019-08-22T13:44:57.172687Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO' 2019-08-22T13:44:57.172698Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS' 2019-08-22T13:44:57.172708Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU' 2019-08-22T13:44:57.172734Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE' 2019-08-22T13:44:57.172746Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET' 2019-08-22T13:44:57.172769Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX' 2019-08-22T13:44:57.172802Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET' 2019-08-22T13:44:57.172814Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM' 2019-08-22T13:44:57.172838Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET' 2019-08-22T13:44:57.172849Z 0 [Note] Shutting down plugin 'INNODB_CMP' 2019-08-22T13:44:57.172872Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS' 2019-08-22T13:44:57.172884Z 0 [Note] Shutting down plugin 'INNODB_LOCKS' 2019-08-22T13:44:57.172895Z 0 [Note] Shutting down plugin 'INNODB_TRX' 2019-08-22T13:44:57.172906Z 0 [Note] Shutting down plugin 'InnoDB' 2019-08-22T13:44:57.173010Z 0 [Note] InnoDB: FTS optimize thread exiting. 2019-08-22T13:44:57.173195Z 0 [Note] InnoDB: Starting shutdown... 2019-08-22T13:44:57.274546Z 0 [Note] InnoDB: Dumping buffer pool(s) to /mysqldata/mysql/ib_buffer_pool 2019-08-22T13:44:57.275296Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 190822 21:44:57 2019-08-22T13:44:58.528547Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2530257 2019-08-22T13:44:58.531650Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2019-08-22T13:44:58.531698Z 0 [Note] Shutting down plugin 'MEMORY' 2019-08-22T13:44:58.531736Z 0 [Note] Shutting down plugin 'CSV' 2019-08-22T13:44:58.531752Z 0 [Note] Shutting down plugin 'sha256_password' 2019-08-22T13:44:58.531764Z 0 [Note] Shutting down plugin 'mysql_native_password' 2019-08-22T13:44:58.531967Z 0 [Note] Shutting down plugin 'binlog' 2019-08-22T13:44:58.532460Z 0 [Note] /mysqlsoft/mysql/bin/mysqld: Shutdown complete
為了在伺服器上自動啟動和停止MySQL服務,你必須在你的/etc/rc*檔案中合適的地方新增啟動和停止命令:
.如果使用Linux服務RPM包(MySQL-server-VERSION.rpm)或一個原生的Linux包安裝,那麼mysql.server指令碼可能以mysqld或mysql的名稱安裝到/etc/init.d目錄中。
.如果使用原始碼或二進位制版本來安裝MySQL時不能自動安裝mysql.server,可以手動安裝這個指令碼。它可以在MySQL安裝目錄或MySQL原始碼樹下的support-files目錄中找到。將這個指令碼複製到/etc/init.d目錄中並命名為mysql並且修改許可權讓其它可以執行:
[root@cs2 ~]# cp /mysqlsoft/mysql/support-files/mysql.server /etc/init.d/mysqld [root@cs2 ~]# chmod 755 /etc/init.d/mysqld
在安裝指令碼後,依賴於作業系統命令需要在系統啟動時來啟用它。在Linux上,你可以使用chkconfig:
[root@localhost init.d]# chkconfig --add mysqld
在有一些Linux系統中,也需要執行以下命令來完全啟用mysqld指令碼:
[root@localhost init.d]# chkconfig --level 345 mysqld on
在FreeBSD系統中,啟動指令碼通常應該在/usr/local/etc/rc.d/目錄中,安裝的mysql.server指令碼就是/usr/local/etc/rc.d/mysql.server.sh來啟用自動啟動。rc(8)手冊頁指出,只有當指令碼的基本名稱與*.sh shell檔名模式匹配時,才會執行該目錄中的指令碼。該目錄中存在的任何其他檔案或目錄都將被預設忽略。
作為上述設定的一種替代方案,有些作業系統也會使用/etc/rc.local或/etc/init.d/boot.local來在作業系統啟動時啟動額外的服務。為了使用這種方法來啟動MySQL。需要在合適的啟動檔案中增加類似下面的命令:
/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
對於其它系統,諮詢你作業系統文件來檢視如何安裝啟動指令碼。
mysql.server會讀取選項檔案中的[mysql.server]和[mysqld]部分的選項。為了向後相容,它也會讀取[mysql_server]部分的選項,但是現在你應該將它重新命名為[mysql.server]。
可以在全域性/etc/my.cnf檔案中為mysql.server增加選項。一個常見的my.cnf檔案可能看到類似於以下所示:
[mysqld] basedir=/mysqlsoft/mysql datadir=/mysqldata/mysql user=mysql port=3306 socket = /mysqlsoft/mysql/mysql.sock [mysql.server] basedir=/usr/local/mysql
mysql.server指令碼支援下表中所列出的選項。如果指定,他們必須被儲存在一個選項檔案中,而不是在命令列中設定。mysql.server只支援start和stop作為命令列引數
表4.4 mysql.server選項檔案選項
Option Name Description Type
basedir MySQL安裝目錄路徑 目錄名
datadir MySQL資料目錄路徑 目錄名
pid-file 伺服器將它的程式ID需要寫入的檔案 檔名
service-startup-timeout 伺服器在啟動時所等待的時間長度 整數
basedir=dir_name
MySQL安裝目錄路徑
datadir=dir_name
MySQL資料目錄路徑
pid-file=file_name
伺服器將它的程式ID需要寫入的檔案的路徑名。如果這個選項沒有指定,mysql.server將使用預設值host_name.pid這種PID檔案值傳送給mysql_safe會覆蓋在[mysqld_safe]選項檔案組中所指定的任何值。因為mysql.server會讀取[mysqld]選項檔案組但不會讀取[mysqld_safe]組,你也可以確保透過在[mysqld_safe]和[mysqld]組中設定相同的pid-file值使用在手動從mysql.server指令碼中呼叫mysqld_safe時可以得到相同的值。
service-startup-timeout=seconds
確認伺服器啟動時可以等待的時間長度。如果伺服器在這個時間內沒有啟動成功,mysql.server會丟擲錯誤並退出。預設時間為900秒。0意味著在啟動時不會執行等待。負數意味著將會永久等待(不會超時)。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2661916/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sql server schedule scriptSQLServer
- MySQL5.7: sql script demoMySql
- startup,startup mount,startup nomount之間的區別
- startup mount與startup restrict mount有何區別REST
- STARTUP FORCE 理解
- Oracle shutdown and startupOracle
- Script
- MySQL server5.7版出現server failedMySqlServerAI
- 【MySQL】檢視MySQL Server引數方法MySqlServer
- Oracle 資料庫啟動 startup和startup force的區別Oracle資料庫
- MySQL server has gone awayMySqlServerGo
- MySQL client server 協議MySqlclientServer協議
- Mysql修改server uuidMySqlServerUI
- Connecting to the MySQL ServerMySqlServer
- MySQL Server架構概述MySqlServer架構
- Script Browser & Script Analyzer 1.3更新發布
- Shell Script
- shell script
- oracle scriptOracle
- script win
- bat scriptBAT
- MySQL:Lost connection to MySQL server at 'readingMySqlServer
- mysql關於mysql.server的總結MySqlServer
- MySQL master and slave have equal MySQL server UUIDsMySqlASTServerUI
- Jetpack之Startup快速掌握Jetpack
- oracle-startup過程Oracle
- Oracle startup mount exclusive作用Oracle
- Forced Startup in Abnormal Situations (292)ORM
- Restricting Access to a Database at StartupRESTDatabase
- MySQL 8.0 Reference Manual(讀書筆記69節--InnoDB Startup Configuration)MySql筆記
- MYSQL The Server Shutdown Process(筆記)MySqlServer筆記
- MySQL Server-id的作用MySqlServer
- script標籤
- [Oracle Script] LockOracle
- Tablespace Space Script
- Cold backup script
- Oracle Database ScriptOracleDatabase
- tom's script