%3CLINGO-SUB%20id%3D%22lingo-sub-1369879%22%20slang%3D%22en-US%22%3ERe%3A%20Best%20Practices%20for%20migrating%20large%20databases%20to%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1369879%22%20slang%3D%22en-US%22%3E%3CP%3ERyan%2C%3C%2FP%3E%3CP%3EThat's%20a%20thorough%20approach.%20I%20like%20it.%3C%2FP%3E%3CP%3EBut%20I%20am%20curious%20of%20why%20you%20didn't%20use%20Azure%20Database%20Migration%20Service%3F%20It%20now%20supports%20MySQL%20(and%20the%20other%20open-source%20database%20products)%20and%20could%20provide%20a%20more%20automated%20process%2C%20unless%20there's%20something%20I'm%20not%20aware%20of.%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3EAndy%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1362699%22%20slang%3D%22en-US%22%3EBest%20Practices%20for%20migrating%20large%20databases%20to%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1362699%22%20slang%3D%22en-US%22%3E%3CP%3ESince%20the%20general%20availability%20of%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fconcepts-pricing-tiers%23storage%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ELarge%20Storage%20(16TB)%20option%3C%2FA%3E%20in%20Azure%20Database%20for%20MySQL%2C%20large%20databases%20in%20dimension%20of%20hundreds%20of%20gigabytes%20to%20multiple%20terabytes%20(up%20to%2016TB)%2C%20and%20workload%20requires%20high%20concurrency%20IO%20such%20as%20OLTP%20workloads%20(up%20to%2020K%20IOPs%20at%20the%20time%20of%20writing%20this)%20is%20now%20supported.%20This%20raises%20an%20important%20question%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%22What%20is%20the%20fastest%20way%20of%20migrating%20your%20large%20databases%3C%2FEM%3E%2C%20%3CEM%3Eeither%20from%20on-premises%20or%20other%20cloud%20environments%20to%20Azure%3C%2FEM%3E%3F%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBased%20on%20our%20experience%20working%20with%20a%20customer%20to%20migrate%20their%20large%20databases%20to%20Azure%2C%20we%20evaluated%20all%20the%20available%20options%20and%20came%20up%20with%20the%20following%20best%20practices.%20This%20blog%20post%20is%20intended%20to%20share%20some%20of%20these%20best%20practices%20on%20migrating%20large%20databases%20to%20Azure%20Database%20for%20MySQL%20to%20help%20other%20customers.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1353600638%22%20id%3D%22toc-hId--1353600638%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907826%22%3E%3C%2FA%3ECustomer%20Scenario%3C%2FH2%3E%0A%3CP%3EWe%20have%20a%20customer%20has%20already%20been%20running%20their%20mission%20critical%20OLTP%20workload%20on%20MySQL%20with%20database%20sized%20at%201.7TB%20(~600GB%20of%20data%20plus%20indexes).%20The%20database%20is%20currently%20running%20on%20legacy%20storage%20and%20customer%20is%20seeking%20to%20migrate%20to%20Azure%20Database%20for%20MySQL%20service%20with%20large%20storage%20to%20take%20the%20advantage%20of%20support%20of%2016TB%20storage%20and%2020%2C000%20IOPS.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1133912195%22%20id%3D%22toc-hId-1133912195%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907827%22%3E%3C%2FA%3EOur%20Considerations%3C%2FH2%3E%0A%3CP%3EThe%20following%20factors%20need%20to%20be%20considered%20on%20course%20of%20planning%20the%20large%20MySQL%20database%20migration%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EThere%20is%20no%20physical%20backup%20facility%20available%20for%20Azure%20Database%20for%20MySQL%20as%20it%20is%20a%20fully%20managed%20service.%20Only%20logical%20backups%2C%20i.e.%20converting%20data%20back%20to%20INSERT%20statements%2C%20is%20supported%3C%2FLI%3E%0A%3CLI%3ETo%20take%20advantage%20of%20file-per-table%20tablespace%2C%20data%20must%20be%20exported%20from%20current%20database%2C%20and%20import%20to%20the%20new%20Large%20Storage%20based%20database%3C%2FLI%3E%0A%3CLI%3ETools%20which%20exploit%20parallelism%20performs%20better%20during%20both%20export%20and%20import%20process%20as%20it%20better%20utilize%20the%20IO%20bandwidth%20available.%20Unfortunately%2C%20the%20mysqldump%20tool%20shipped%20with%20MySQL%20package%20does%20not%20support%20this%2C%20however%20we%20have%20community%20tools%20like%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmaxbube%2Fmydumper%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emydumper%3C%2FA%3E%20which%20supports%20parallel%20logical%20backups%20(export)%20and%20restore%20(import).%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--673542268%22%20id%3D%22toc-hId--673542268%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907828%22%3E%3C%2FA%3EApproach%3C%2FH2%3E%0A%3CP%3EGiven%20the%20considerations%20above%2C%20we%20have%20devised%20the%20following%20migration%20strategy%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ESet%20up%20an%20Azure%20VM%20for%20temporary%20storage%20of%20backups%20and%20to%20install%20backup%2Frestore%20client.%3C%2FLI%3E%0A%3CLI%3EInstall%20mysql%20client%20tools%20and%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmaxbube%2Fmydumper%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emydumper%3C%2FA%3E%20in%20the%20Azure%20VM%20(we%20assume%20our%20readers%20are%20using%20Ubuntu%20Linux%20here).%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3Esudo%20apt-get%20install%20mysql-client%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3Ewget%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmaxbube%2Fmydumper%2Freleases%2Fdownload%2Fv0.9.5%2Fmydumper_0.9.5-1.xenial_amd64.debdpkg%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fmaxbube%2Fmydumper%2Freleases%2Fdownload%2Fv0.9.5%2Fmydumper_0.9.5-1.xenial_amd64.debdpkg%3C%2FA%3E%20-i%20mydumper_0.9.5-1.xenial_amd64.deb%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3EIf%20the%20source%20database%20is%20used%20for%20mission%20critical%20application%2C%20provision%20a%20read%20replica%20of%20the%20source%20from%20which%20the%20logical%20backup%20using%20mydumper%20will%20be%20sourced%20to%20avoid%20any%20interference%20of%20the%20logical%20backup%20on%20the%20production%20workload.%3C%2FLI%3E%0A%3CLI%3EExport%20the%20schema%20using%20the%20MySQL%20shipped%20tools%20mysqldump.%3C%2FLI%3E%0A%3CLI%3EExport%20data%20from%20source%20MySQL%20server%20to%20the%20temporary%20VM%20using%20mydumper%2C%20which%20support%20multi-threaded%20data%20export.%3C%2FLI%3E%0A%3CLI%3EProvision%20Azure%20Database%20for%20MySQL%20server%20with%20the%20right%20configurations%20and%20compute%2Fstorage%20settings%2C%20which%20will%20form%20the%20target%20destination%20to%20restore.%3C%2FLI%3E%0A%3CLI%3EImport%20data%20from%20the%20temporary%20VM%20into%20the%20new%20instance%20of%20Azure%20MySQL%20using%20myloader%2C%20which%20also%20support%20multi-threaded%20data%20import.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22large_mysqldb_migrate.png%22%20style%3D%22width%3A%20348px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F189430iA5E922728D0DC979%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22large_mysqldb_migrate.png%22%20alt%3D%22large_mysqldb_migrate.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorryantam_mshk_0%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CH2%20id%3D%22toc-hId-1813970565%22%20id%3D%22toc-hId-1813970565%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907829%22%3E%3C%2FA%3EPrepare%20for%20data%20migration%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1790435257%22%20id%3D%22toc-hId--1790435257%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907830%22%3E%3C%2FA%3ECreate%20a%20temporary%20VM%3C%2FH3%3E%0A%3CP%3EAny%20General-Purpose%20family%20Linux%20VM%20would%20serve%20the%20purpose.%20Ubuntu%20should%20benefit%20customer%20since%20it%20is%20the%20VM%20with%20lowest%20cost.%20The%20VM%20should%20have%20at%20least%204%20vCore%20and%2016GB%20of%20memory%2C%20with%20support%20and%20enablement%20of%20%3CSTRONG%3EAccelerated%20Networking%3C%2FSTRONG%3E%20to%20provide%20a%20stable%20network.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20Premium%20Disk%20should%20be%20added%20to%20the%20VM%20to%20store%20the%20exported%20data.%20Prefer%20to%20be%20sized%20at%20least%201TB%20or%20above%20(P30%20tier%20or%20higher)%20to%20leverage%20the%205000%2B%20IOPS%20and%20200%2BMB%2Fsecond%20throughput%20per%20disk%3CA%20href%3D%22%23_ftn1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20name%3D%22_ftnref1%22%3E%3CSPAN%3E%5B1%5D%3C%2FSPAN%3E%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20temporary%20VM%20should%20also%20be%20in%20the%20same%20VNet%20as%20the%20source%20and%20target%20MySQL%20server%20to%20ensure%20connectivity.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-697077576%22%20id%3D%22toc-hId-697077576%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907831%22%3E%3C%2FA%3ECreate%20and%20setup%20Azure%20Database%20for%20MySQL%3C%2FH3%3E%0A%3CP%3ECreate%20a%20new%20instance%20of%20Azure%20MySQL.%20It%20is%20recommended%20to%20apply%20the%20following%20settings%20before%20the%20migration%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Emax_allowed_packet%20%E2%80%93%20set%20to%20%3CSTRONG%3E1073741824%3C%2FSTRONG%3E%20(i.e.%201GB)%20to%20prevent%20any%20overflow%20issue%20due%20to%20long%20rows%3C%2FLI%3E%0A%3CLI%3Eslow_query_log%20%E2%80%93%20set%20to%20%3CSTRONG%3EOFF%3C%2FSTRONG%3E%20to%20turn%20off%20the%20slow%20query%20log.%20This%20will%20eliminate%20the%20overhead%20causing%20by%20slow%20query%20logging%3C%2FLI%3E%0A%3CLI%3Equery_store_capture_mode%20%E2%80%93%20set%20both%20to%20%3CSTRONG%3ENONE%3C%2FSTRONG%3E%20to%20turn%20off%20the%20Query%20Store.%20This%20will%20eliminate%20the%20overhead%20causing%20by%20sampling%20activities%20by%20Query%20Store.%3C%2FLI%3E%0A%3CLI%3Einnodb_buffer_pool_size%20%E2%80%93%20%3CSTRONG%3EScale%20up%3C%2FSTRONG%3E%20the%20server%20to%2032%20vCore%20Memory%20Optimized%26nbsp%3BSKU%20from%20the%20Pricing%20tier%20of%20the%20portal%20during%20migration%20to%20increase%20the%20innodb_buffer_pool_size.%20Innodb_buffer_pool_size%20cannot%20be%20increased%20without%20scaling%20up%20compute%20for%20Azure%20Database%20for%20MySQL%20server.%3C%2FLI%3E%0A%3CLI%3Einnodb_write_io_threads%20%26amp%3B%20innodb_write_io_threads%20-%20Change%20to%20%3CSTRONG%3E16%3C%2FSTRONG%3E%20from%20the%20Server%20parameters%20in%20Azure%20portal%20to%20improve%20the%20speed%20of%20migration.%3C%2FLI%3E%0A%3CLI%3EScale%20up%20Storage%20tier%20%E2%80%93%20The%20IOPs%20for%20Azure%20Database%20for%20MySQL%20server%20increases%20progressively%20with%20the%20increase%20in%20storage%20tier.%20For%20faster%20loads%2C%20you%20may%20want%20to%20provide%20%3CSTRONG%3Eat%20the%20least%204TB%3C%2FSTRONG%3E%20to%20get%2012K%20IOPs.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId--1110376887%22%20id%3D%22toc-hId--1110376887%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907832%22%3E%3C%2FA%3EVirtual%20Network%3C%2FH3%3E%0A%3CP%3EYou%20should%20make%20the%20following%20virtual%20network%20(VNet)%20related%20settings%20to%20secure%20all%20the%20traffic%20during%20data%20migration%20and%20preventing%20the%20traffic%20routed%20through%20public%20endpoints%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIn%20the%20VNet%20where%20the%20temporary%20VM%20has%20been%20connected%20with%2C%20add%20%3CSTRONG%3EMicrosoft.Sql%3C%2FSTRONG%3E%20to%20the%20service%20endpoint%20of%20the%20subnet%20the%20temporary%20VM%20at.%20This%20with%20allow%20Azure%20MySQL%20traffic%20route%20through%20the%20VNet%20and%20subnet%3C%2FLI%3E%0A%3CLI%3EIn%20the%20%3CSTRONG%3EConnection%20Security%3C%2FSTRONG%3E%20setting%20of%20the%20new%20Azure%20MySQL%20instance%2C%20add%20the%20virtual%20network%20and%20subnet%20which%20the%20temporary%20VM%20situated%20at.%20This%20will%20allow%20network%20traffic%20route%20through%20the%20whitelisted%20VNet%20and%20subnet%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1120879991%22%20id%3D%22toc-hId--1120879991%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907833%22%3E%3C%2FA%3EBest%20practice%20on%20migration%3C%2FH2%3E%0A%3CP%3EThis%20section%20will%20highlight%20the%20best%20practices%20on%20migrating%20large%20MySQL%20databases%2C%20particularly%20the%20special%20parameters%20we%20recommend%20to%20apply%20during%20the%20migration%20process.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--430318517%22%20id%3D%22toc-hId--430318517%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907834%22%3E%3C%2FA%3EExport%20the%20Schema%3C%2FH3%3E%0A%3CP%3ESince%20the%20size%20of%20the%20schema%20will%20be%20limited%2C%20we%E2%80%99ll%20use%20mysqldump%2C%20the%20original%20data%20dumping%20tool%20shipped%20with%20MySQL%2C%20to%20complete%20the%20task%20of%20schema%20export.%3C%2FP%3E%0A%3CP%3EWhen%20running%20mysqldump%2C%20use%20the%20following%20parameters%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E--no-data%E2%80%93%20prevent%20table%20contents%20from%20being%20dump%3C%2FLI%3E%0A%3CLI%3E--column-statistics%3D0%20%E2%80%93%20if%20you%20have%20installed%20MySQL%20command%20line%20tools%20version%208.0%20instead%20of%205.7%2C%20you%20must%20set%20this%20parameter%20to%200%20to%20prevent%20the%20following%20error%20which%20is%20caused%20by%20new%20feature%20in%20MySQL%208.0%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3E%3CEM%3EUnknown%20table%20'COLUMN_STATISTICS'%20in%20information_schema%20(1109)%3C%2FEM%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E--add-drop-database%20and%20--add-drop-table%20(optional)%20%E2%80%93%20the%20script%20will%20drop%20the%20existing%20database%20and%20table%20before%20creating%20the%20new%20one%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId-2057194316%22%20id%3D%22toc-hId-2057194316%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907835%22%3E%3C%2FA%3EExport%20the%20Data%3C%2FH3%3E%0A%3CP%3EInstead%20of%20the%20single-threaded%20mysqldump%2C%20we%E2%80%99ll%20use%20%3CSTRONG%3EMyDumper%3C%2FSTRONG%3E%20which%20support%20multi-threaded%20data%20export%2C%20to%20speed%20up%20the%20export%20process.%20Apply%20the%20following%20mydumper%20parameters%20to%20speed%20up%20the%20export%20process%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E--no-schemas%E2%80%93%20the%20schema%20will%20be%20created%20by%20the%20schema%20script%20exported%20in%20above%20step%3C%2FLI%3E%0A%3CLI%3E--compress-protocol%20%E2%80%93%20enable%20client%20compression%20protocol%20to%20compress%20the%20data%20sent%20between%20VM%20and%20MySQL%20server%3C%2FLI%3E%0A%3CLI%3E--threads%20%E2%80%93%20use%20a%20value%20equal%20to%202x%20of%20the%20vCore%20of%20the%20temporary%20VM%3C%2FLI%3E%0A%3CLI%3E--chunk-filesize%20%E2%80%93%20split%20large%20tables%20into%20chunk%20of%20file%20size.%20This%20will%20allow%20large%20table%20to%20be%20imported%20in%20parallel%2C%20recommended%20in%20the%20range%20of%20512%20to%201024MB%3C%2FLI%3E%0A%3CLI%3E--statement-size%20%E2%80%93%20set%20to%20104857600%20(bytes)%20to%20allow%20generation%20of%20extra%20long%20rows%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId--445423626%22%20id%3D%22toc-hId--445423626%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907836%22%3E%3C%2FA%3EImport%20the%20schema%3C%2FH3%3E%0A%3CP%3EUse%20the%20%3CSTRONG%3Emysql%3C%2FSTRONG%3E%20command%20line%20tool%20to%20import%20the%20schema.%20No%20special%20parameter%20need%20to%20be%20applied.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3Emysql%20%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3Eu%20%3C%2FSPAN%3E%3CSPAN%3E%26lt%3B%3C%2FSPAN%3E%3CSPAN%3Euser%3C%2FSPAN%3E%3CSPAN%3E%26gt%3B%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3Ep%20%3C%2FSPAN%3E%3CSPAN%3E%26lt%3B%3C%2FSPAN%3E%3CSPAN%3E%20db_backup%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Edump%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-2042089207%22%20id%3D%22toc-hId-2042089207%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907837%22%3E%3C%2FA%3EDrop%20the%20indexes%20temporarily%3C%2FH3%3E%0A%3CP%3EIf%20possible%2C%20drop%20the%20indexes%20before%20the%20data%20import%20to%20reduce%20IO%20burden%20on%20storage.%20Indexes%20can%20be%20recreated%20after%20the%20data%20import%20completed.%20However%20it%20may%20not%20be%20possible%20if%20you%20have%20a%20complex%20schema%20with%20a%20lot%20of%20foreign%20key%20constraints.%20Consider%20the%20time%20and%20effort%20require%20to%20prepare%20scripts%20for%20drop%2Frecreate%20the%20index%20against%20your%20migration%20timeline.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20use%20the%20following%20script%20to%20generate%20script%20to%20drop%20and%20recreate%20all%20the%20indexes%20in%20your%20schema%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EDrop%20Indexes%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ESELECT%26nbsp%3BCONCAT('ALTER%26nbsp%3BTABLE%26nbsp%3B'%2C%26nbsp%3BSUBSTRING_INDEX(SUBSTRING_INDEX(t.name%2C%26nbsp%3B'%2F'%2C%26nbsp%3B2)%2C%26nbsp%3B'%2F'%2C%26nbsp%3B-1)%2C%26nbsp%3B'%26nbsp%3BDROP%26nbsp%3BINDEX%26nbsp%3B'%2C%26nbsp%3Bi.name%2C%26nbsp%3B'%3B')%26nbsp%3BAS%26nbsp%3B'drop_idx_sql'%3C%2FP%3E%0A%3CP%3EFROM%26nbsp%3Binformation_schema.innodb_sys_tables%26nbsp%3Bt%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BINNER%26nbsp%3BJOIN%26nbsp%3Binformation_schema.innodb_sys_indexes%26nbsp%3Bi%26nbsp%3BUSING%26nbsp%3B(table_id)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BINNER%26nbsp%3BJOIN%26nbsp%3Binformation_schema.innodb_sys_fields%26nbsp%3Bf%26nbsp%3BUSING%26nbsp%3B(index_id)%3C%2FP%3E%0A%3CP%3EWHERE%26nbsp%3BSUBSTRING_INDEX(SUBSTRING_INDEX(t.name%2C%26nbsp%3B'%2F'%2C%26nbsp%3B1)%2C%26nbsp%3B'%2F'%2C%26nbsp%3B-1)%26nbsp%3Blike%26nbsp%3B'%24DB'%3C%2FP%3E%0A%3CP%3EGROUP%26nbsp%3BBY%26nbsp%3Bt.name%2C%26nbsp%3Bi.name%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3ERe-create%20Indexes%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ESELECT%26nbsp%3BCONCAT('CREATE%26nbsp%3BINDEX%26nbsp%3B'%2C%26nbsp%3Bi.name%2C%26nbsp%3B'%26nbsp%3BON%26nbsp%3B'%2C%26nbsp%3BSUBSTRING_INDEX(SUBSTRING_INDEX(t.name%2C%26nbsp%3B'%2F'%2C%26nbsp%3B2)%2C%26nbsp%3B'%2F'%2C%26nbsp%3B-1)%2C%26nbsp%3B'%26nbsp%3B('%2C%26nbsp%3BGROUP_CONCAT(f.name%26nbsp%3BORDER%26nbsp%3BBY%26nbsp%3Bf.pos)%2C%26nbsp%3B')%3B'%26nbsp%3B)%26nbsp%3BAS%26nbsp%3B'create_idx_sql'%26nbsp%3B%5C%3C%2FP%3E%0A%3CP%3EFROM%26nbsp%3Binformation_schema.innodb_sys_tables%26nbsp%3Bt%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BINNER%26nbsp%3BJOIN%26nbsp%3Binformation_schema.innodb_sys_indexes%26nbsp%3Bi%26nbsp%3BUSING%26nbsp%3B(table_id)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BINNER%26nbsp%3BJOIN%26nbsp%3Binformation_schema.innodb_sys_fields%26nbsp%3Bf%26nbsp%3BUSING%26nbsp%3B(index_id)%3C%2FP%3E%0A%3CP%3EWHERE%26nbsp%3BSUBSTRING_INDEX(SUBSTRING_INDEX(t.name%2C%26nbsp%3B'%2F'%2C%26nbsp%3B1)%2C%26nbsp%3B'%2F'%2C%26nbsp%3B-1)%26nbsp%3Blike%26nbsp%3B'%24DB'%3C%2FP%3E%0A%3CP%3EGROUP%26nbsp%3BBY%26nbsp%3Bt.name%2C%26nbsp%3Bi.name%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-234634744%22%20id%3D%22toc-hId-234634744%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907838%22%3E%3C%2FA%3EImport%20the%20data%3C%2FH3%3E%0A%3CP%3E%3CSTRONG%3EMyLoader%3C%2FSTRONG%3E%2C%20the%20multi-threaded%20import%20tool%2C%20shall%20be%20used%20in%20conjunction%20with%20MyDumper%20using%20the%20following%20recommended%20parameters%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E--queries-per-transaction%20%E2%80%93%20recommend%20to%20set%20to%20value%20not%20more%20than%20500%3C%2FLI%3E%0A%3CLI%3E--compress-protocol%20%E2%80%93%20enable%20client%20compression%20protocol%20to%20compress%20the%20data%20sent%20between%20VM%20and%20MySQL%20server%3C%2FLI%3E%0A%3CLI%3E--threads%20%E2%80%93%20use%20a%20value%20equal%20to%202x%20of%20the%20vCore%20of%20the%20temporary%20VM%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1701902438%22%20id%3D%22toc-hId--1701902438%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907839%22%3E%3C%2FA%3EOther%20applicable%20Scenarios%3C%2FH2%3E%0A%3CP%3EBesides%20the%20mentioned%20customer%20scenario%2C%20there%20are%20other%20scenarios%20which%20may%20benefit%20from%20the%20best%20practices%20above%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EVersion%20upgrades%20%E2%80%93%20since%20there%20is%20no%20direct%20upgrade%20from%20MySQL%20version%205.7%20to%208.0%20in%20Azure%20yet%2C%20data%20export%20and%20import%20will%20be%20required%20and%20using%20the%20same%20approach%20as%20this%20document%3C%2FLI%3E%0A%3CLI%3EMigrate%20from%20Azure%20Database%20for%20MySQL%20legacy%20(4TB%20max)%20storage%20to%20new%20large%20(16TB%20max)%20storage%20%E2%80%93%20similar%20approach.%20The%20data%20and%20schema%20export%20can%20be%20done%20on%20Azure%20VMs%20before%20copying%20the%20exported%20data%20and%20schema%20to%20the%20temporary%20VM%20on%20Azure.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-785610395%22%20id%3D%22toc-hId-785610395%22%3E%3CA%20target%3D%22_blank%22%20name%3D%22_Toc38907840%22%3E%3C%2FA%3EFurther%20Reading%3C%2FH2%3E%0A%3CP%3EFor%20additional%20information%2C%20please%20refer%20to%20the%20following%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EAzure%20Database%20for%20MySQL%20documentation%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2F%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3Emydumper%2Fmyloader%20project%20in%20GitHub%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmaxbube%2Fmydumper%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fmaxbube%2Fmydumper%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22%23_ftnref1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20name%3D%22_ftn1%22%3E%3CSPAN%3E%5B1%5D%3C%2FSPAN%3E%3C%2FA%3E%20Disk%20type%20available%20for%20Azure%20VM%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fwindows%2Fdisks-types%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fwindows%2Fdisks-types%3C%2FA%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--892761349%22%20id%3D%22toc-hId--892761349%22%3E%26nbsp%3B%3C%2FH3%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1362699%22%20slang%3D%22en-US%22%3E%3CP%3EHave%20large%20MySQL%20databases%20moving%20or%20going%20to%20move%20to%20Azure%3F%20This%20blog%20post%20share%20the%20best%20practices%20on%20doing%20so%2C%20based%20on%20our%20real-world%20experience.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft

Since the general availability of Large Storage (16TB) option in Azure Database for MySQL, large databases in dimension of hundreds of gigabytes to multiple terabytes (up to 16TB), and workload requires high concurrency IO such as OLTP workloads (up to 20K IOPs at the time of writing this) is now supported. This raises an important question:

 

"What is the fastest way of migrating your large databases, either from on-premises or other cloud environments to Azure?"

 

Based on our experience working with a customer to migrate their large databases to Azure, we evaluated all the available options and came up with the following best practices. This blog post is intended to share some of these best practices on migrating large databases to Azure Database for MySQL to help other customers.

 

Customer Scenario

We have a customer has already been running their mission critical OLTP workload on MySQL with database sized at 1.7TB (~600GB of data plus indexes). The database is currently running on legacy storage and customer is seeking to migrate to Azure Database for MySQL service with large storage to take the advantage of support of 16TB storage and 20,000 IOPS.

 

Our Considerations

The following factors need to be considered on course of planning the large MySQL database migration:

  1. There is no physical backup facility available for Azure Database for MySQL as it is a fully managed service. Only logical backups, i.e. converting data back to INSERT statements, is supported
  2. To take advantage of file-per-table tablespace, data must be exported from current database, and import to the new Large Storage based database
  3. Tools which exploit parallelism performs better during both export and import process as it better utilize the IO bandwidth available. Unfortunately, the mysqldump tool shipped with MySQL package does not support this, however we have community tools like mydumper which supports parallel logical backups (export) and restore (import).

 

Approach

Given the considerations above, we have devised the following migration strategy:

  1. Set up an Azure VM for temporary storage of backups and to install backup/restore client.
  2. Install mysql client tools and mydumper in the Azure VM (we assume our readers are using Ubuntu Linux here).

sudo apt-get install mysql-client

wget https://github.com/maxbube/mydumper/releases/download/v0.9.5/mydumper_0.9.5-2.xenial_amd64.deb -i mydumper_0.9.5-2.xenial_amd64.deb

 

  1. If the source database is used for mission critical application, provision a read replica of the source from which the logical backup using mydumper will be sourced to avoid any interference of the logical backup on the production workload.
  2. Export the schema using the MySQL shipped tools mysqldump.
  3. Export data from source MySQL server to the temporary VM using mydumper, which support multi-threaded data export.
  4. Provision Azure Database for MySQL server with the right configurations and compute/storage settings, which will form the target destination to restore.
  5. Import data from the temporary VM into the new instance of Azure MySQL using myloader, which also support multi-threaded data import.

       large_mysqldb_migrate.png

 

 

Prepare for data migration

 

Create a temporary VM

Any General-Purpose family Linux VM would serve the purpose. Ubuntu should benefit customer since it is the VM with lowest cost. The VM should have at least 4 vCore and 16GB of memory, with support and enablement of Accelerated Networking to provide a stable network.

 

A Premium Disk should be added to the VM to store the exported data. Prefer to be sized at least 1TB or above (P30 tier or higher) to leverage the 5000+ IOPS and 200+MB/second throughput per disk[1].

 

The temporary VM should also be in the same VNet as the source and target MySQL server to ensure connectivity.

 

Create and setup Azure Database for MySQL

Create a new instance of Azure MySQL. It is recommended to apply the following settings before the migration:

  • max_allowed_packet – set to 1073741824 (i.e. 1GB) to prevent any overflow issue due to long rows
  • slow_query_log – set to OFF to turn off the slow query log. This will eliminate the overhead causing by slow query logging
  • query_store_capture_mode – set both to NONE to turn off the Query Store. This will eliminate the overhead causing by sampling activities by Query Store.
  • innodb_buffer_pool_size – Scale up the server to 32 vCore Memory Optimized SKU from the Pricing tier of the portal during migration to increase the innodb_buffer_pool_size. Innodb_buffer_pool_size cannot be increased without scaling up compute for Azure Database for MySQL server.
  • innodb_write_io_threads & innodb_write_io_threads - Change to 16 from the Server parameters in Azure portal to improve the speed of migration.
  • Scale up Storage tier – The IOPs for Azure Database for MySQL server increases progressively with the increase in storage tier. For faster loads, you may want to provide at the least 4TB to get 12K IOPs.

Virtual Network

You should make the following virtual network (VNet) related settings to secure all the traffic during data migration and preventing the traffic routed through public endpoints:

  • In the VNet where the temporary VM has been connected with, add Microsoft.Sql to the service endpoint of the subnet the temporary VM at. This with allow Azure MySQL traffic route through the VNet and subnet
  • In the Connection Security setting of the new Azure MySQL instance, add the virtual network and subnet which the temporary VM situated at. This will allow network traffic route through the whitelisted VNet and subnet

 

Best practice on migration

This section will highlight the best practices on migrating large MySQL databases, particularly the special parameters we recommend to apply during the migration process.

 

Export the Schema

Since the size of the schema will be limited, we’ll use mysqldump, the original data dumping tool shipped with MySQL, to complete the task of schema export.

When running mysqldump, use the following parameters:

  • --no-data– prevent table contents from being dump
  • --column-statistics=0 – if you have installed MySQL command line tools version 8.0 instead of 5.7, you must set this parameter to 0 to prevent the following error which is caused by new feature in MySQL 8.0:

Unknown table 'COLUMN_STATISTICS' in information_schema (1109)

  • --add-drop-database and --add-drop-table (optional) – the script will drop the existing database and table before creating the new one

Export the Data

Instead of the single-threaded mysqldump, we’ll use MyDumper which support multi-threaded data export, to speed up the export process. Apply the following mydumper parameters to speed up the export process:

  • --no-schemas– the schema will be created by the schema script exported in above step
  • --compress-protocol – enable client compression protocol to compress the data sent between VM and MySQL server
  • --threads – use a value equal to 2x of the vCore of the temporary VM
  • --chunk-filesize – split large tables into chunk of file size. This will allow large table to be imported in parallel, recommended in the range of 512 to 1024MB
  • --statement-size – set to 104857600 (bytes) to allow generation of extra long rows

Import the schema

Use the mysql command line tool to import the schema. No special parameter need to be applied.

mysql -u <user> -p < db_backup.dump

 

Drop the indexes temporarily

If possible, drop the indexes before the data import to reduce IO burden on storage. Indexes can be recreated after the data import completed. However it may not be possible if you have a complex schema with a lot of foreign key constraints. Consider the time and effort require to prepare scripts for drop/recreate the index against your migration timeline.

 

You may use the following script to generate script to drop and recreate all the indexes in your schema:

Drop Indexes

SELECT CONCAT('ALTER TABLE ', SUBSTRING_INDEX(SUBSTRING_INDEX(t.name, '/', 2), '/', -1), ' DROP INDEX ', i.name, ';') AS 'drop_idx_sql'

FROM information_schema.innodb_sys_tables t

    INNER JOIN information_schema.innodb_sys_indexes i USING (table_id)

    INNER JOIN information_schema.innodb_sys_fields f USING (index_id)

WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(t.name, '/', 1), '/', -1) like '$DB'

GROUP BY t.name, i.name;

 

Re-create Indexes

SELECT CONCAT('CREATE INDEX ', i.name, ' ON ', SUBSTRING_INDEX(SUBSTRING_INDEX(t.name, '/', 2), '/', -1), ' (', GROUP_CONCAT(f.name ORDER BY f.pos), ');' ) AS 'create_idx_sql' \

FROM information_schema.innodb_sys_tables t

    INNER JOIN information_schema.innodb_sys_indexes i USING (table_id)

    INNER JOIN information_schema.innodb_sys_fields f USING (index_id)

WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(t.name, '/', 1), '/', -1) like '$DB'

GROUP BY t.name, i.name;

 

Import the data

MyLoader, the multi-threaded import tool, shall be used in conjunction with MyDumper using the following recommended parameters:

  • --queries-per-transaction – recommend to set to value not more than 500
  • --compress-protocol – enable client compression protocol to compress the data sent between VM and MySQL server
  • --threads – use a value equal to 2x of the vCore of the temporary VM

 

Other applicable Scenarios

Besides the mentioned customer scenario, there are other scenarios which may benefit from the best practices above:

  1. Version upgrades – since there is no direct upgrade from MySQL version 5.7 to 8.0 in Azure yet, data export and import will be required and using the same approach as this document
  2. Migrate from Azure Database for MySQL legacy (4TB max) storage to new large (16TB max) storage – similar approach. The data and schema export can be done on Azure VMs before copying the exported data and schema to the temporary VM on Azure.

 

Further Reading

For additional information, please refer to the following:

 

[1] Disk type available for Azure VM: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-types

 

3 Comments
Frequent Visitor

Ryan,

That's a thorough approach. I like it.

But I am curious of why you didn't use Azure Database Migration Service? It now supports MySQL (and the other open-source database products) and could provide a more automated process, unless there's something I'm not aware of.

Thanks,

Andy

Microsoft

@Andrew Snodgrass thanks for your comment. DMS is a Migration-as-a-Service which in effect letting us to migrate the database on our customer and save developers effort. However there are scenarios where our customers have compliance or regulatory requirements on data handling, which require them to migrate their database (which likely storing sensitive data) by themselves rather through a managed service.

 

Thanks,

Ryan

Frequent Visitor

Ryan,

Excellent reasoning. Thank you...