您好,登錄后才能下訂單哦!
本篇內容介紹了“怎么理解并掌握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意味著在啟動時不會執行等待。負數意味著將會永久等待(不會超時)。
“怎么理解并掌握MySQL Server Startup Script”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。