| 導購 | 订阅 | 在线投稿
分享
 
 
 

MySQL5.1體驗--MySQL實例管理器mysqlmanager初試

來源:互聯網網民  2008-05-21 09:45:31  評論

MySQL實例管理器(IM)是通過TCP/IP端口運行的後台程序,用來監視和管理MySQL數據庫服務器實例。MySQL實例管理器適合Unix-類操作系統和Windows。

可以在mysqld_safe腳本使用MySQL實例管理器來啓動和停止MySQL服務器,甚至可以從一個遠程主機。MySQL實例管理器還執行mysqld_multi腳本的功能(和大多數語法)。

一、 mysqlmanager 配置文件

一個最常見的 mysqlmanager 配置文件如下:

[manager]port= 1999socket= /tmp/manager.sockpid-file= /tmp/manager.pidrun-as-service= truemonitoring-interval= 10default-mysqld-path= /usr/local/mysql/bin/mysqldpassword-file = /etc/mysqlmanager.passwdlog=/usr/local/mysql/bin/mysqld/mysqlmanager.log[mysqld1]basedir = /usr/local/mysqldatadir = /usr/local/mysql/data1general-log= truelog-error= /usr/local/mysql/data1/error.logpid-file= /usr/local/mysql/data1/mysql.pidport = 13306socket= /tmp/mysql13306.sock[mysqld2]basedir = /usr/local/mysqldatadir = /usr/local/mysql/data2general-log= truelog-error= /usr/local/mysql/data2/error.logpid-file= /usr/local/mysql/data2/mysql.pidport = 13307socket= /tmp/mysql13307.sock[mysqld3]basedir = /usr/local/mysqldatadir = /usr/local/mysql/data3general-log= truelog-error= /usr/local/mysql/data3/error.logpid-file= /usr/local/mysql/data3/mysql.pidport = 13308socket= /tmp/mysql13308.sock

首先,第一個區間是 [manager],它用于指定 mysqlmanager 程序啓動時的選項。其中 run-as-service 選項是指 mysqlmanager 以後台守護進程方式運行, default-mysqld-path 選項則指定了 mysqld 程序所在的位置。 password-file 選項則指定了連接到 mysqlmanager 的用戶密碼文件所在位置。

接下來,後面的 [mysqld1], [mysqld2], [mysqld3] 區間則分別設定了3個 MySQL 運行實例。這些參數就是常見的設置了,在這裏不再細說。

二、 mysqlmanager 用戶管理

1、添加用戶

[root@localhost]# /usr/local/mysql/bin/mysqlmanager --add-user --username=yejr[20910/136318976] [07/06/19 11:03:01] [INFO] IM: started.[20910/136318976] [07/06/19 11:03:01] [INFO] Loading config file 'my.cnf'...[20910/136318976] [07/06/19 11:03:01] [INFO] Loading the password database...[20910/136318976] [07/06/19 11:03:01] [INFO] The password database loaded successfully.Enter password:Re-type password:[20910/136318976] [07/06/19 11:03:04] [INFO] IM: finished.[root@localhost]# [root@localhost]# cat /etc/mysqlmanager.passwdyejr:*0E558D9FBD602CDA0C9F3F7A8BC5F4F53401CD7C

2、修改密碼

[root@localhost]# /usr/local/mysql/bin/mysqlmanager --edit-user --username=yejr[20943/136318976] [07/06/19 11:05:01] [INFO] IM: started.[20943/136318976] [07/06/19 11:05:01] [INFO] Loading config file 'my.cnf'...[20943/136318976] [07/06/19 11:05:01] [INFO] Loading the password database...[20943/136318976] [07/06/19 11:05:01] [INFO] Loaded user 'yejr'.[20943/136318976] [07/06/19 11:05:01] [INFO] The password database loaded successfully.Enter password:Re-type password:[20943/136318976] [07/06/19 11:05:05] [INFO] IM: finished.[root@localhost]# [root@localhost]# cat /etc/mysqlmanager.passwdyejr:*9DB91006131E32B22135599033C6A9C196EC3C6B

3、刪除用戶

[root@localhost]# /usr/local/mysql/bin/mysqlmanager --drop-user --username=yejr[20967/136318976] [07/06/19 11:06:30] [INFO] IM: started.[20967/136318976] [07/06/19 11:06:30] [INFO] Loading config file 'my.cnf'...[20967/136318976] [07/06/19 11:06:30] [INFO] Loading the password database...[20967/136318976] [07/06/19 11:06:30] [INFO] Loaded user 'yejr'.[20967/136318976] [07/06/19 11:06:30] [INFO] The password database loaded successfully.[20967/136318976] [07/06/19 11:06:30] [INFO] IM: finished.

默認情況下,mysqlmanager 的密碼文件是 /etc/mysqlmanager.passwd,如果你的密碼文件不是放在這裏,那麽就需要自行指定,增加一個參數 --password-file=path_to_passwd_file,讓 mysqlmanager 根據指定的位置去找到正確的密碼文件。如:

[root@localhost]# /usr/local/mysql/bin/mysqlmanager --password-file=/usr/local/mysql/.mysqlmanager.passwd --add-user --username=yejr

注意:修改或者刪除用戶後,只有重啓 mysqlmanager 才能生效,而不是立刻生效。

三、 mysqlmanager 管理

1、mysqlmanager 啓動

[root@localhost]# /usr/local/mysql/bin/mysqlmanager --defaults-file=/usr/local/mysql/my.cnf[21032/136318976] [07/06/19 11:11:03] [INFO] IM: started.[21032/136318976] [07/06/19 11:11:03] [INFO] Loading config file '/usr/local/mysql/my.cnf'...[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: started.[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: opening log file '/usr/local/mysql/bin/mysqld/mysqlmanager.log'...[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: daemonizing...[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: exiting from the original process...[21032/136318976] [07/06/19 11:11:03] [INFO] IM: finished.[21033/136318976] [07/06/19 11:11:03] [INFO] Angel: preparing standard streams.

在啓動 mysqlmanager 的同時,也會把它管理的所有 MySQL實例 全部啓動。

[root@localhost]# mysql -uyejr -P1999 -hlocalhost -S/tmp/manager.sock -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1 to server version: 1.0-betaType 'help;' or '\h' for help. Type '\c' to clear the buffer.(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+--------+| instance_name | state |+---------------+--------+| mysqld1 | online || mysqld2 | online || mysqld3 | online |+---------------+--------+

2、mysqlmanager 狀態查看

(yejr:localhost:)(none)> SHOW INSTANCE STATUS mysqld1\G*************************** 1. row *************************** instance_name: mysqld1 state: online version_number: 5.1.19 version: 5.1.19-beta for unknown-freebsd6.0 on i386 (MySQL Community Server (GPL))mysqld_compatible: no(yejr:localhost:)(none)> SHOW INSTANCE OPTIONS mysqld1;+---------------+----------------------------------------------+| option_name | value |+---------------+----------------------------------------------+| instance_name | mysqld1 || basedir | /usr/local/mysql || datadir | /usr/local/mysql/data1 || general-log | true || log-error | /usr/local/mysql/data1/error.log || pid-file | /usr/local/mysql/data1/mysql.pid || port | 13306 || socket | /tmp/mysql13306.sock |+---------------+----------------------------------------------+(yejr:localhost:)(none)> SHOW mysqld1 LOG FILES;+-----------+----------------------------------+-----------+| Logfile | Path | File size |+-----------+----------------------------------+-----------+| ERROR LOG | /usr/local/mysql/data1/error.log | 2976 |+-----------+----------------------------------+-----------+(yejr:localhost:)(none)> SHOW mysqld13306 LOG ERROR 2976\G*************************** 1. row ***************************070619 11:17:57 [Warning] Server variable data_file_path of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable data_home_dir of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable flush_method of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable log_arch_dir of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable log_group_home_dir of plugin InnoDB was forced to be read-only: stringvariable without update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 InnoDB: Started; log sequence number 0 48402070619 11:17:57 [Note] Event Scheduler: Loaded 0 events070619 11:17:57 [Note] /usr/local/mysql/bin/mysqld: ready for connections.Version: '5.1.19-beta' socket: '/tmp/mysql13306.sock' port: 13306 MySQL Community Server (GPL)

更多的可操作命令可以參考手冊。

3、mysqlmanager 管理

停止 MySQL實例:

(yejr:localhost:)(none)> STOP INSTANCE mysqld1;Query OK, 0 rows affected (1.81 sec)(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+---------+| instance_name | state |+---------------+---------+| mysqld1 | offline || mysqld2 | online || mysqld3 | online |+---------------+---------+(yejr:localhost:)(none)> START INSTANCE mysqld1;Query OK, 0 rows affected (0.00 sec)Instance started(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+--------+| instance_name | state |+---------------+--------+| mysqld1 | online || mysqld2 | online || mysqld3 | online |+---------------+--------+(yejr:localhost:)(none)> STOP INSTANCE mysqld2;Query OK, 0 rows affected (1.81 sec)(yejr:localhost:)(none)> STOP INSTANCE mysqld3;Query OK, 0 rows affected (1.81 sec)(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+---------+| instance_name | state |+---------------+---------+| mysqld1 | offline || mysqld2 | offline || mysqld3 | offline |+---------------+---------+(yejr:localhost:)(none)> FLUSH INSTANCES;Query OK, 0 rows affected (0.09 sec)(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+--------+| instance_name | state |+---------------+--------+| mysqld1 | online || mysqld2 | online || mysqld3 | online |+---------------+--------+

在 MySQL實例 停止的狀態下,還可以動態的修改端口等參數。

注意: FLUSH INSTANCES 語法會在 MySQL 5.2 以後不再使用。

總結:通過 mysqlmanager 我們就可以遠程來管理 mysqld,包括重啓,查看日志,設定系統參數等。而無需直接登錄服務器或者通過 mysql 客戶端登錄服務器,也進一步保護了 MySQL 賬戶的安全,這在有較多數量的 MySQL 服務器引用環境中還是很有幫助的。

 
特别声明:以上内容(如有图片或视频亦包括在内)为网络用户发布,本站仅提供信息存储服务。
 
  MySQL實例管理器(IM)是通過TCP/IP端口運行的後台程序,用來監視和管理MySQL數據庫服務器實例。MySQL實例管理器適合Unix-類操作系統和Windows。   可以在mysqld_safe腳本使用MySQL實例管理器來啓動和停止MySQL服務器,甚至可以從一個遠程主機。MySQL實例管理器還執行mysqld_multi腳本的功能(和大多數語法)。   一、 mysqlmanager 配置文件   一個最常見的 mysqlmanager 配置文件如下:   [manager]port = 1999socket = /tmp/manager.sockpid-file= /tmp/manager.pidrun-as-service = truemonitoring-interval = 10default-mysqld-path = /usr/local/mysql/bin/mysqldpassword-file = /etc/mysqlmanager.passwdlog = /usr/local/mysql/bin/mysqld/mysqlmanager.log[mysqld1]basedir = /usr/local/mysqldatadir = /usr/local/mysql/data1general-log = truelog-error = /usr/local/mysql/data1/error.logpid-file = /usr/local/mysql/data1/mysql.pidport = 13306socket = /tmp/mysql13306.sock[mysqld2]basedir = /usr/local/mysqldatadir = /usr/local/mysql/data2general-log = truelog-error = /usr/local/mysql/data2/error.logpid-file = /usr/local/mysql/data2/mysql.pidport = 13307socket = /tmp/mysql13307.sock[mysqld3]basedir = /usr/local/mysqldatadir = /usr/local/mysql/data3general-log = truelog-error = /usr/local/mysql/data3/error.logpid-file = /usr/local/mysql/data3/mysql.pidport = 13308socket = /tmp/mysql13308.sock   首先,第一個區間是 [manager],它用于指定 mysqlmanager 程序啓動時的選項。其中 run-as-service 選項是指 mysqlmanager 以後台守護進程方式運行, default-mysqld-path 選項則指定了 mysqld 程序所在的位置。 password-file 選項則指定了連接到 mysqlmanager 的用戶密碼文件所在位置。   接下來,後面的 [mysqld1], [mysqld2], [mysqld3] 區間則分別設定了3個 MySQL 運行實例。這些參數就是常見的設置了,在這裏不再細說。   二、 mysqlmanager 用戶管理   1、添加用戶   [root@localhost]# /usr/local/mysql/bin/mysqlmanager --add-user --username=yejr[20910/136318976] [07/06/19 11:03:01] [INFO] IM: started.[20910/136318976] [07/06/19 11:03:01] [INFO] Loading config file 'my.cnf'...[20910/136318976] [07/06/19 11:03:01] [INFO] Loading the password database...[20910/136318976] [07/06/19 11:03:01] [INFO] The password database loaded successfully.Enter password:Re-type password:[20910/136318976] [07/06/19 11:03:04] [INFO] IM: finished.[root@localhost]# [root@localhost]# cat /etc/mysqlmanager.passwdyejr:*0E558D9FBD602CDA0C9F3F7A8BC5F4F53401CD7C   2、修改密碼   [root@localhost]# /usr/local/mysql/bin/mysqlmanager --edit-user --username=yejr[20943/136318976] [07/06/19 11:05:01] [INFO] IM: started.[20943/136318976] [07/06/19 11:05:01] [INFO] Loading config file 'my.cnf'...[20943/136318976] [07/06/19 11:05:01] [INFO] Loading the password database...[20943/136318976] [07/06/19 11:05:01] [INFO] Loaded user 'yejr'.[20943/136318976] [07/06/19 11:05:01] [INFO] The password database loaded successfully.Enter password:Re-type password:[20943/136318976] [07/06/19 11:05:05] [INFO] IM: finished.[root@localhost]# [root@localhost]# cat /etc/mysqlmanager.passwdyejr:*9DB91006131E32B22135599033C6A9C196EC3C6B   3、刪除用戶   [root@localhost]# /usr/local/mysql/bin/mysqlmanager --drop-user --username=yejr[20967/136318976] [07/06/19 11:06:30] [INFO] IM: started.[20967/136318976] [07/06/19 11:06:30] [INFO] Loading config file 'my.cnf'...[20967/136318976] [07/06/19 11:06:30] [INFO] Loading the password database...[20967/136318976] [07/06/19 11:06:30] [INFO] Loaded user 'yejr'.[20967/136318976] [07/06/19 11:06:30] [INFO] The password database loaded successfully.[20967/136318976] [07/06/19 11:06:30] [INFO] IM: finished.   默認情況下,mysqlmanager 的密碼文件是 /etc/mysqlmanager.passwd,如果你的密碼文件不是放在這裏,那麽就需要自行指定,增加一個參數 --password-file=path_to_passwd_file,讓 mysqlmanager 根據指定的位置去找到正確的密碼文件。如:   [root@localhost]# /usr/local/mysql/bin/mysqlmanager --password-file=/usr/local/mysql/.mysqlmanager.passwd --add-user --username=yejr   注意:修改或者刪除用戶後,只有重啓 mysqlmanager 才能生效,而不是立刻生效。   三、 mysqlmanager 管理   1、mysqlmanager 啓動   [root@localhost]# /usr/local/mysql/bin/mysqlmanager --defaults-file=/usr/local/mysql/my.cnf[21032/136318976] [07/06/19 11:11:03] [INFO] IM: started.[21032/136318976] [07/06/19 11:11:03] [INFO] Loading config file '/usr/local/mysql/my.cnf'...[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: started.[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: opening log file '/usr/local/mysql/bin/mysqld/mysqlmanager.log'...[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: daemonizing...[21032/136318976] [07/06/19 11:11:03] [INFO] Angel: exiting from the original process...[21032/136318976] [07/06/19 11:11:03] [INFO] IM: finished.[21033/136318976] [07/06/19 11:11:03] [INFO] Angel: preparing standard streams.   在啓動 mysqlmanager 的同時,也會把它管理的所有 MySQL實例 全部啓動。   [root@localhost]# mysql -uyejr -P1999 -hlocalhost -S/tmp/manager.sock -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1 to server version: 1.0-betaType 'help;' or '\h' for help. Type '\c' to clear the buffer.(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+--------+| instance_name | state |+---------------+--------+| mysqld1 | online || mysqld2 | online || mysqld3 | online |+---------------+--------+   2、mysqlmanager 狀態查看   (yejr:localhost:)(none)> SHOW INSTANCE STATUS mysqld1\G*************************** 1. row *************************** instance_name: mysqld1 state: online version_number: 5.1.19 version: 5.1.19-beta for unknown-freebsd6.0 on i386 (MySQL Community Server (GPL))mysqld_compatible: no(yejr:localhost:)(none)> SHOW INSTANCE OPTIONS mysqld1;+---------------+----------------------------------------------+| option_name | value |+---------------+----------------------------------------------+| instance_name | mysqld1 || basedir | /usr/local/mysql || datadir | /usr/local/mysql/data1 || general-log | true || log-error | /usr/local/mysql/data1/error.log || pid-file | /usr/local/mysql/data1/mysql.pid || port | 13306 || socket | /tmp/mysql13306.sock |+---------------+----------------------------------------------+(yejr:localhost:)(none)> SHOW mysqld1 LOG FILES;+-----------+----------------------------------+-----------+| Logfile | Path | File size |+-----------+----------------------------------+-----------+| ERROR LOG | /usr/local/mysql/data1/error.log | 2976 |+-----------+----------------------------------+-----------+(yejr:localhost:)(none)> SHOW mysqld13306 LOG ERROR 2976\G*************************** 1. row ***************************070619 11:17:57 [Warning] Server variable data_file_path of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable data_home_dir of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable flush_method of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable log_arch_dir of plugin InnoDB was forced to be read-only: string variablewithout update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 [Warning] Server variable log_group_home_dir of plugin InnoDB was forced to be read-only: stringvariable without update_func and PLUGIN_VAR_MEMALLOC flag070619 11:17:57 InnoDB: Started; log sequence number 0 48402070619 11:17:57 [Note] Event Scheduler: Loaded 0 events070619 11:17:57 [Note] /usr/local/mysql/bin/mysqld: ready for connections.Version: '5.1.19-beta' socket: '/tmp/mysql13306.sock' port: 13306 MySQL Community Server (GPL)   更多的可操作命令可以參考手冊。   3、mysqlmanager 管理   停止 MySQL實例:   (yejr:localhost:)(none)> STOP INSTANCE mysqld1;Query OK, 0 rows affected (1.81 sec)(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+---------+| instance_name | state |+---------------+---------+| mysqld1 | offline || mysqld2 | online || mysqld3 | online |+---------------+---------+(yejr:localhost:)(none)> START INSTANCE mysqld1;Query OK, 0 rows affected (0.00 sec)Instance started(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+--------+| instance_name | state |+---------------+--------+| mysqld1 | online || mysqld2 | online || mysqld3 | online |+---------------+--------+(yejr:localhost:)(none)> STOP INSTANCE mysqld2;Query OK, 0 rows affected (1.81 sec)(yejr:localhost:)(none)> STOP INSTANCE mysqld3;Query OK, 0 rows affected (1.81 sec)(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+---------+| instance_name | state |+---------------+---------+| mysqld1 | offline || mysqld2 | offline || mysqld3 | offline |+---------------+---------+(yejr:localhost:)(none)> FLUSH INSTANCES;Query OK, 0 rows affected (0.09 sec)(yejr:localhost:)(none)> SHOW INSTANCES;+---------------+--------+| instance_name | state |+---------------+--------+| mysqld1 | online || mysqld2 | online || mysqld3 | online |+---------------+--------+   在 MySQL實例 停止的狀態下,還可以動態的修改端口等參數。   注意: FLUSH INSTANCES 語法會在 MySQL 5.2 以後不再使用。   總結:通過 mysqlmanager 我們就可以遠程來管理 mysqld,包括重啓,查看日志,設定系統參數等。而無需直接登錄服務器或者通過 mysql 客戶端登錄服務器,也進一步保護了 MySQL 賬戶的安全,這在有較多數量的 MySQL 服務器引用環境中還是很有幫助的。
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有