

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、Mysql安裝和維護手冊目錄1 .在 Linux 下安裝 Mysql . 31.1 RPM 安裝 MySQL. 31.2 源碼安裝 mysql . 41.3 Mysql 管理 . 63 .Mysql 的配置管理 . 84 .Mysql 復制管理 . 124.1 現有分布式數據庫架構 . 124.2 主從異步同步配置操作實例 . 124.3 半同步復制 . 145 .Mysql 多實例配置 . 151.在Linux下安裝Mysql1.1 RPM 安裝 MySQL建議在 Linux 中使用 RPM 包來安裝 MySQL 。 MySQL RPM 目前已經嵌入到 SuSE Linux 7.3 系統中,
2、但是應當能在大多數支持rpm 和使用 glibc 的 Linux 版本中工作。MySQL AB 不提供與具體平臺相關的 RPM ;具體平臺相關的 RPM 和通用 RPM 之間的區 別是具體平臺相關 RPM 為目標平臺而構建,為動態連接。而通用 RPM 與 Linux 線程之間是 靜態連接。注釋: 通常由其它供應商提供 MySQL 的 RPM 分發版。 其特征和功能與 MySQL AB 所構 建的不同, 該手冊中的指令不一定適合安裝其它供應商提供的 MySQL 的 RPM 分發版。 此時 應咨詢供應商的說明。在大多數情況, 你只需要安裝 MySQL-server 和 MySQL-client 軟
3、件包來安裝 MySQL 。在 標準安裝中不需要其它的包。如果安裝 MySQL 軟件包時出現從屬錯誤 (例如, “ error:removing these packages would breakdependencies: libmysqlclient.so.10 is needed by . ”,) 你 還 應 當 安 裝 包 MySQL-shared-compat ,其 中 包 括 兩 個 向 后 兼 容 的 共 享 庫(MySQL 4.0 為libmysqlclient.so.12 ,MySQL 3.23 為libmysqlclient.so.10) 。可以使用以下 RPM 包:MySQ
4、L-server-VERSION.glibc23.i386.rpmMySQL 服務器。你需要該選項,除非你只想連接運行在另一臺機器上的 MySQL 服務 器。 注釋:在 MySQL 4.0.10 之前,服務器 RPM 文件被稱為 MySQL-VERSION.i386.rpm。也 就是說,名稱中不含有 -server。MySQL-clie nt-VERSION.glibc23.i386.rpm標準 MySQL 客戶端程序。你可能總是要安裝該軟件包。MySQL-devel-VERSION.glibc23.i386.rpm庫和包含文件,如果你想要編譯其它 MySQL 客戶端,例如 Perl 模塊,則
5、需要。MySQL-shared-VERSION.glibc23.i386.rpm該軟件包包含某些語言和應用程序需要動態裝載的共享庫(libmysqlclient.so*) ,使用MySQL 。 MySQL-shared-compat-VERSION.glibc23.i386.rpm該軟件包包括 MySQL 3.23 和 MySQL 4.0 的共享庫。如果你安裝了應用程序動態連接 MySQL3.23 ,但是你想要升級到 MySQL 4.0 而不想打破庫的從屬關系, 則安裝該軟件包而不 要安裝MySQL-shared 。從 MySQL 4.0.13 起包含該安裝軟件包。 MySQL-embedde
6、d-VERSION.glibc23.i386.rpm嵌入式 MySQL 服務器庫 (從 MySQL 4.0 起)。 MySQL-VERSION.glibc23.i386.rpm包含以前所有軟件包的源碼。 可用來在其它架構上重建 RPM( 例如, Alpha 或 SPARC)。 要想看到 RPM 軟件包內的所有文件 (例如, MySQL-server RPM) ,運行:shell rpm -qpl MySQL-server- VERSION .i386.rpm要想執行標準最小安裝,運行:shell rpm -i MySQL-server- VERSION .i386.rpmshell rpm -
7、i MySQL-client- VERSION .i386.rpm要想只安裝客戶端軟件包,運行:shell rpm -i MySQL-client- VERSION .i386.rpm RPM 提供在安裝軟件包前驗證其完整性和真實性的功能。服務器 RPM 將數據放入 /var/lib/mysql 目錄。 RPM 還為 mysql 用戶創建登錄賬戶 (如果還 沒有),用來運行 MySQL 服務器,并在 /etc/init.d/ 創建相應條目,以便在引導時自動啟動服務 器。 ( 這意味著如果你已經安裝并且已經更改啟動腳本,你可能要復制腳本,以便你安裝新 RPM 時 不會丟掉腳本 )。如果想要在舊的
8、不支持 /etc/init.d( 直接或通過符號連接 ) 初始化腳本的 Linux 分發版中安 裝MySQL RPM ,你應當創建一個指向初始化腳本實際安裝的位置的符號連接。例如,如果 安裝位置為/etc/rc.d/init.d ,安裝 RPM 前使用這些命令創建 /etc/init.d ,作為指向該位置的符號 連接:shell cd /etcshell ln -s rc.d/init.d 。目前主要 Linux 分發版應當支持使用 /etc/init.d 的新目錄布局,因為需要 LSB(Linux 標準基 ) 兼容性。如果你安裝的 RPM 文件包括 MySQL-server ,安裝后 MyS
9、QL d 服務器應當能啟動并運行。 你 應當能使用 MySQL 啟動。注釋: MySQL 授權表中的賬戶開始沒有密碼。1.2 源碼安裝 mysql本節介紹在各種平臺上安裝 tar 壓縮文件格式的 MySQL 二進制分發版 ( 文件有 .tar.gz 擴 展名 )。MySQL tar 文件二進制分 發版的 文件名 格式為 mysql-VERSION-OS.tar.gz,其 中 VERSION 是版本號 ( 例如, 5.1.2-alpha) , OS 表示分發版安裝的操作系統類型 (例如, pc-linux-i686) 。你需要下面的工具來安裝 MySQL tar 文件二進制分發版:GNU gun
10、 zip 解壓縮分發版。一個適當的 tar 解包分發版。 GNU tar 已知可以。一些操作系統中含有預安裝的tar,已知有問題。例如,已知 Mac OS X tar 和 Sun tar 對于長文件名有問題。在 Mac OS X 中,你可 以使用預安裝的 gnutar 程序。在其它系統中若 tar 不完善,你應當首先安裝 GNU tar 。cmake No version limitlibtool 1.5GNU make 3.79bis on 1.75gcc 2.95 必須執行以便安裝并使用 MySQL 二進制分發版的基本命令是:Linux 系統的 Root 用戶安裝:# Preconfigu
11、ration setupshell groupadd mysqlshell useradd -r -g mysql mysql# Beginning of source-build specific instructions shell tarzxvf mysql-5.5.15.tar.gz shell cd mysql-5.5.15 shellcmake .shell make shellmake install# End of source-build specific instructions# Postinstallation setup shell cd /usr/local/mys
12、ql shellchown -R mysql . shell chgrp -R mysql . shellscripts/mysql_install_db -user=mysqlshell chown -R root .shell chown -R mysql data# Next command is optionalshellcp support- /etc/fshellbin/mysqld_safe -user=mysql & # Next command is optional,可選命令shellcp support- /etc/init.d/mysql.serverLinux
13、 系統的普通用戶 Mysql 用戶安裝:# Beginning of source-build specific instructions shell tarzxvf mysql-5.5.15.tar.gz shell cd mysql-5.5.15 shellcmake -DCMAKE_INSTALL_PREFIX=/dir . shell makeshellmake install# End of source-build specific instructions# Postinstallation setup shell cd /dir shellscripts/mysql_insta
14、ll_db -user=mysql# Next command is optional shellcp support-/dir/etc/fshellbin/mysqld_safe -user=mysql & #下面為安裝二進制分發版的更詳細的描述:1. 為 mysqld 增加一個登錄用戶和組:2.shell groupadd mysql3.shell useradd -g mysql mysql4. Shell tar zxvf mysq-l5.5.15.tar.gz5.進入安裝目錄: shell cd mysql-5.5.156.編譯安裝 mysql: shell cmake .
15、shell make啟動 mysql啟動 mysqlshell make installMysql 編譯參數指定示例:cmake -DCMAKE_INSTALL_PREFIX=/home/kmsdb1/iddbs/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_E
16、NGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/home/kmsdb1/iddbs/mysql1/data -DMYSQL_USER=kmsdb1shell scripts/mysql_install_db -user=mysql/home/kmsdb1/iddbs/mysql1/scripts/mysql_install_db-user=kmsdb1-defaults-basedir=/home/kmsdb1/iddbs/mysql1-data
17、dir=/home/kmsdb1/iddbs/mysql1/data-user=kmsdb18將程序二進制的所有權改為root,數據目錄的所有權改為運行mysqld 的用戶。如果位于安裝目錄 (/usr/local/mysql) 下,命令應為:shell chown -R root shell chown -R mysql data shell chgrp -R mysql 第一個命令將文件的所有屬性改為 root 用戶。第二個命令將數據目錄的所有屬性改為 mysql 用戶。第三個命令將組屬性改為mysql 組。8如果你喜歡在引導機器時自動啟動MySQL,可以拷貝 support-文件到系統有
18、啟動文件的地方。9可以用下列命令啟動 MySQL 服務器:shell bin/mysqld_safe -user=mysql &注釋: MySQL 授權表中的賬戶開始沒有密碼。啟動服務器后,應當設置密碼。1.3 Mysql 管理啟動 Mysql :/usr/local/mysql/bin/mysqld_safe -user=mysql&登陸 Mysql:/usr/local/mysql/bin/mysql #使用默認用戶登錄停止 Mysql :/usr/local/mysql/bin/mysqladmin shutdown連接命令 ( 可選其一 ) :mysql -h134.6
19、4.114.242 -P3306 -umysql -pmysqlmysql -umysql -p -P3306 -S /tmp/mysql3306.sock 輸入密碼 進入7. 初始化 mysql:初始化示例:2 .Mysql 的配置管理Mysql 的配置管理文件為/etc/f,配置文件設置了的 mysql 的配置管理參 數。如果需要對 mysql 進行配置管理,修改/etc/f 文件然后重啟 mysql 即可 生效。Mysql 的配置參數共有 321 個,所有配置參數都有默認值,可以不在配置文件中 配置。將需要修改的配置參數配置在配置文件中即可。Mysql 配置文件模板示例:# The fo
20、llowing options will be passed to all MySQL clients client#password= your_passwordport = 3306socket= /tmp/mysql.sock# Here follows entries for some specific programs# The MySQL server mysqldport = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 384Mmax_allowed_packet = 1M table
21、_open_cache = 512 sort_buffer_size = 2M read_buffer_size = 2Mread_rnd_buffer_size = 8M myisam_sort_buffer_size = 64M thread_cache_size = 8query_cache_size = 32M# Try number of CPUs*2 for thread_concurrency thread_concurrency = 8# Dont listen on a TCP/IP port at all. This can be a security enhancemen
22、t,# if all processes that need to connect to mysqld run on the same host.# All interaction with mysqld must be made via Unix sockets or named pipes.# Note that using this option without enabling named pipes on Windows# (via the enable-named-pipe option) will render mysqld useless!#skip-networking# R
23、eplication Master Server (default)# binary logging is required for replication log-bin=mysql-bin# required unique id betwee n 1 and 2A32 - 1# defaults to 1 if master-host is not set# but will not function as a master if omitted server-id = 1# Replication Slave (comment out master section to use this
24、)# To configure this host as a replication slave, you can choose between# two methods :# 1) Use the CHANGE MASTER TO command (fully described in our manual) -#the syntax is:#CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,#MASTER_USER=, MASTER_PASSWORD= ;# where you replace , , by quoted strings and# by
25、 the masters port number (3306 by default).#Example:#CHANGE MASTER TO MASTER_HOST=125.564.12.1, MASTER_PORT=3306,#MASTER_USER=joe, MASTER_PASSWORD=secret;# OR# 2) Set the variables below. However, in case you choose this method, then#start replication for the first time (even unsuccessfully, for exa
26、mple#if you mistyped the password in master-password and the slave fails to# connect), the slave will create a file, and any later# change in this the variables values below will be ignored and# overridden by the content of the file, unless you shutdown# the slave server, del
27、ete and restart the slaver server.# For that reason, you may want to leave the lines below untouched# (commented) and instead use CHANGE MASTER TO (see above)# required unique id betwee n 2 and 2A32 - 1# (and different from the master)# defaults to 2 if master-host is set# but will not f
28、unction as a slave if omitted#server-id= 2# The replication master for this slave - required#master-host = # The username the slave will use for authentication when connecting# to the master - required#master-user = # The password the slave will authenticate with when connecting to# the master - req
29、uired#master-password = # The port the master is listening on.# optional - defaults to 3306#master-port = # binary logging - not required for slaves, but recommended#log-bin=mysql-bin# binary logging format - mixed recommended#binlog_format=mixed# Uncomment the following if you are using InnoDB tabl
30、es #innodb_data_home_dir =/usr/local/mysql/data #innodb_data_ = ibdata1:2000M;ibdata2:10M:autoextend#innodb_log_group_home_dir = /usr/local/mysql/data# You can set ._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 384M#innodb_additional
31、_mem_pool_size = 20M# Set ._log_ to 25 % of buffer pool size#innodb_log_ = 100M#innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1_ _ _ _#innodb_lock_wait_timeout = 50mysqldumpquickmax_allowed_packet = 16Mmysqlno-auto-rehash# Remove the next comment character if you are not familiar wit
32、h SQL #safe-updatesmyisamchkkey_buffer_size = 256Msort_buffer_size = 256M read_buffer = 2Mwrite_buffer = 2Mmysqlhotcopy interactive-timeout3 .Mysql 復制管理MySQL 支持異步復制、半同步復制。復制過程中一個服務器充當主服務器, 而一個或多個其它服務器充當從服務器。主服務器將更新寫入二進制日志文件, 這些日志記錄被發送到從服務器。從服務器接收任何更新日志,然后重新執行這 些更新日志。 這里有異步復制、半同步復制兩種模式。3.1 現有分布式數據庫架構
33、搭建環境中:Mysql master-1Mysql master-33.2 主從異步同步配置操作實例注意:配置主從同步時 master 和 slave 的配置文件中的 server-id(整數值)要配置為不同。1.Mysql master-1 配置操作步驟:(1)創建數據同步的用戶GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO rep% IDENTIFIED BYrepl;(2)執行 SHOW MASTER STATUS;查看日志點結果:mysql ehow master status;+- +- - -卜File| 口osntion
34、 | Bi nlog_Do_DB Binlog_Iqriore_DF;I mysql-bln,000015 |529 |+- -卡 - T-+-卜1 row In set 0.00三乂)iriyql 2.Mysql master-2 配置操作步驟:和 Mysql master-2 互為主從同步和MysqlProxyMysql master-1Mysql master-2Mysql master-3Mysql master-4(1)執行以下語句來定義連接master 服務器:CHANGE MASTER TO MASTER_HOST= 1, #主 mysql IPMASTER
35、_PORT=3306 ,#主 mysql PortMASTER_USER=repl,MASTER_PASSWORD=repl,#主 mysql 的同步用戶和密碼MASTER_LOG_FILE=mysql-bin.000015,#主 mysql 的日志文件MASTER_LOG_POS=529;#主 mysql 的日志文件的positi on(2) 啟動 slave: mysqlstart slave; #停止 slave:mysqlstop slave;(3) 執行SHOW SLAVE STATUSG語句:結果:mysql 如果 Slave_IO_Running: Yes ,Slave_SQL_
36、Running: Yes 這兩項為 yes 說明主從同步配置成 功。然后按照 Master2 為主,Master1 為從再次配置,即可實現主主互備配置。mysql show slave usG企筍也融出占*1應甘出w晳蟲釧也皆皆腎也瞥材也出自MasTr_nost: MasTer_user : MasTr_Por t:匚cnnecT.Rerry: M-aster_LDg_Fi le:Rd_Misxer_Log_Pos : Relay_Log_Fne: R也ay_Log_Pos : Relay_Mj5ter_Log_rne:3live_lc_R.unni ng: slive_QL_Runni ng
37、: Repl1 CaTe_DO_DB : ReplicaTe_ignore_DB:口電色_DB_Teb1邑:Repl1caTe_iqnore_iabl: Repncxe_w1 I cLoo-iabl e: Rpl icate-Wilri-ignore:LasT.Errnn: Last_Error:skip_countar:Exec_MasTer_Log_PO5:he!ay_Log_5pace: unr-il_condi11 n: urrti l_Log_File: urr1l_Loq_Pa;:MasTer_55i_ 11 onad:Mster_S5L,CA_Fi 1 e:Mi5tr_5SL_C
38、A_Pat h:MasTer_5SL_cerr: MasTer_SSL_Cipher:MasTar_5L_Kay: 5cands_Beh1nd_la5ter : MastLify_5erver_Cert :LsT_IO_Errno: L65T_IO_Error: Lat_蘭QL_楚廣r no : La5T_SQL_Error: Rep1catE_lgncre_server_lds : Flister_5ervGr _ld : 1 row In set (0.00 sec)|fl。卯W*廿百背燈也!皆叼七出也歸曲歸WMW看出qk世首甘WiH百Wiirlngfar master rn send呂J
39、色mt 172,21. 3.177repl330660mysql-bi n.0000051D7i ddbsstorigel-relay-bin.000004 25?myrql-bi n. 000005res&5001075 &3None0NO0No003.3 半同步復制在采用半同步復制時,配置按照下面方式進行:1.在 Mysql master-1 端操作:mysql INSTALL PLUGIN rpl_semi_sync_master SONAME semisync_master.so;修改配置文件f內容如下,然后重啟mysqlmysqldrpl_semi_sync_mast
40、er_enabled=1rpl_semi_sync_master_timeout=1000 # 1 second2.在 Mysql master-2 端mysql INSTALL PLUGIN rpl_semi_sync_slave SONAME semisync_slave.so;修改配置文件f內容如下,然后重啟mysqlmysqldrpl_semi_sync_slave_enabled=13.在 Mysql master-1 和 Mysql master-2 再按照同步配置的方法進行配置即可,實現半同步 復制。4 .Mysql 多實例配置Mysql 多實例是指在一臺服務器上啟動多個運行的 mysql 實例。 多實例配置操作內
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 江蘇省蘇北地區達標名校2025屆初三5月聯考英語試題試卷試卷含答案
- 煙臺大學《系統空間設計》2023-2024學年第二學期期末試卷
- 銀川第二中學2024-2025學年高三五月中旬物理試題含解析
- 木工勞務分包合同
- 江蘇省鹽城市東臺第一教育集團2024-2025學年初三第十一模(最后一卷)英語試題含答案
- 山東工業職業學院《西醫臨床技能訓練》2023-2024學年第二學期期末試卷
- 信陽職業技術學院《現代農業技術導論(種植類)》2023-2024學年第二學期期末試卷
- 新疆維吾爾巴音郭楞蒙古自治州且末縣2025屆五年級數學第二學期期末檢測模擬試題含答案
- 云南省蒙自一中2025屆高三4月模擬考試(一模)語文試題含解析
- 上海市十一校2025年高三第一次調研考試英語試題理試題含解析
- 難治性癌痛護理評估
- 句式變換題型歸類-2024年高考語文二輪復習(新高考專用)(解析版)
- 人員密集場所消防安全管理培訓
- 寵物物流運送服務化協議范本
- 數字經濟學-測試題及答案
- 制造業生產流程標準化管理手冊
- 放射工作人員合同(2篇)
- 《石鐘山記》課件統編版高中語文選擇性必修下冊
- 廣西某農貿市場建設項目可行性研究報告
- 第二屆全國設備管理與智能運維職業技能競賽(電氣設備點檢員)考試題庫(含答案)
- 江蘇省常州市2024年中考物理試題【附參考答案】
評論
0/150
提交評論