Home
%3CLINGO-SUB%20id%3D%22lingo-sub-830404%22%20slang%3D%22en-US%22%3EUpgrade%20from%20Basic%20to%20General%20Purpose%20or%20Memory%20Optimized%20tiers%20in%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-830404%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EYou%20can%20create%20an%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%3EAzure%20Database%20for%20MySQL%3C%2FA%3Eserver%20using%20one%20of%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fmysql%2Fconcepts-pricing-tiers%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%3Ethree%20different%20pricing%20tiers%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%3A%20Basic%2C%20General%20Purpose%2C%20and%20Memory%20Optimized.%20Each%20tier%20is%20differentiated%20by%20the%20amount%20of%20compute%20in%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EvCores%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bthat%20can%20be%20provisioned%2C%20the%20memory%20per%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EvCore%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%2C%20and%20the%20IOPS%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eguaranteed.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EYou%20can%20scale%20a%20server%20between%20the%20General%20Purpose%20and%20Memory%20Optimized%20tiers.%20However%2C%20today%20there%20isn%E2%80%99t%20an%20automated%20way%20to%20change%20a%20server%20from%20the%20Basic%20tier%20to%20the%20General%20Purpose%20or%20Memory%20Optimized%20tiers.%20You%20can%20use%20the%20bash%20script%20below%20to%20simplify%20migrating%20existing%20databases%20from%20a%20Basic%20server%20to%20a%20General%20Purpose%20or%20Memory%20Optimized%20server.%E2%80%AF%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%E2%80%AF%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233117%26quot%3B%3Atrue%2C%26quot%3B134233118%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335551550%26quot%3B%3A6%2C%26quot%3B335551620%26quot%3B%3A6%2C%26quot%3B335559740%26quot%3B%3A240%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20run%20the%20bash%20script%20from%20a%20VM%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fcloud-shell%2Fquickstart%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eor%20Azure%20Cloud%20Shell%3C%2FA%3E).%20First%2C%20verify%20that%20you%20have%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fcli%2Fazure%2Finstall-azure-cli%3Fview%3Dazure-cli-latest%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Einstalled%20latest%20version%20of%20Azure%20CLI%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20the%20mysql%20client%20tools%3CSPAN%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdev.mysql.com%2Fdownloads%2Fmysql%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emysql%20and%20mysqldump%3C%2FA%3E%3C%2FSPAN%3E.%20Because%20MySQL%20utilities%20such%20as%20%3CSPAN%3Emysql%2Fmysqldump%3C%2FSPAN%3Eare%20not%20necessarily%20forward%20compatible%2C%20be%20sure%20to%20use%20the%20same%20version%20of%26nbsp%3B%3CSPAN%3Emysql%2Fmysqldump%3C%2FSPAN%3Eas%20the%20MySQL%20version%20of%20the%20target%20database.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20the%20latest%20version%20of%20the%20script%2C%20please%20visit%20our%20GitHub%20repo%3A%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-mysql%2Fblob%2Fmaster%2Fscripts%2Fmysqlmigrate.sh%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FAzure%2Fazure-mysql%2Fblob%2Fmaster%2Fscripts%2Fmysqlmigrate.sh%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%23!%2Fbin%2Fbash%0A%23%0A%23%20PURPOSE%0A%23%20Migrate%20Azure%20Database%20for%20MySQL%20Server%20from%20Basic%20Pricing%20Tier%20to%20General%20Purpose%2FMemory%20Optimized%20Pricing%20Tier%0A%23%20%0A%23%20DESCRIPTION%0A%23%20Pricing%20tiers%20in%20Azure%20Database%20for%20MySQL%20-%20Single%20Server%0A%23%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fconcepts-pricing-tiers%0A%23%20%0A%23%20Currently%20modifying%20pricing%20tier%20(to%20and%20from%20Basic)%20is%20not%20yet%20supported.%20%0A%23%20This%20script%20helps%20in%20migrating%20an%20existing%20database%20from%20Basic%20Pricing%20Tier%20to%20%0A%23%20General%20Purpose%2FMemory%20Optimized%20Pricing%20Tier.%20%0A%23%20This%20script%20uses%20mysqldump%20to%20extract%20a%20MySQL%20database%20into%20a%20dump%20file%0A%23%20and%20mysql%20to%20restore%20the%20MySQL%20database%20from%20an%20archive%20file%20created%20by%20mysqldump.%0A%23%0A%23%20Migrate%20your%20MySQL%20database%20using%20dump%20and%20restore%0A%23%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fhowto-migrate-using-dump-and-restore%0A%23%0A%23%20PREREQUISITES%0A%23%20Azure%20CLI%20(https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Finstall-azure-cli%3Fview%3Dazure-cli-latest)%0A%23%20mysql-client%20tools%20-%20mysqldump%20and%20mysql%20(https%3A%2F%2Fdev.mysql.com%2Fdownloads%2Fmysql%2F)%0A%23%20%0A%23%20NOTE%0A%23%20Target%20server%20and%20database%20are%20created%20in%20this%20script.%0A%23%20Please%20modify%20the%20script%20to%20specify%20different%20options%20for%20creation%0A%23%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Fmysql%2Fserver%3Fview%3Dazure-cli-latest%0A%23%20%0A%23%20USAGE%0A%23%20bash%20mysqlmigrate.sh%0A%23%20%20%20%20%20%20%20%20%20--source-subscription-id%20'ffffffff-ffff-ffff-ffff-ffffffffffff'%0A%23%20%20%20%20%20%20%20%20%20--source-resource-group-name%20'sourceRG'%0A%23%20%20%20%20%20%20%20%20%20--source-server-name%20'sourcemysql'%0A%23%20%20%20%20%20%20%20%20%20--source-username%20'sourceuser'%0A%23%20%20%20%20%20%20%20%20%20--source-password%20'P%40ssw0rd1'%0A%23%20%20%20%20%20%20%20%20%20--source-database-name%20'sourcedb'%0A%23%20%20%20%20%20%20%20%20%20--target-subscription-id%20'ffffffff-ffff-ffff-ffff-ffffffffffff'%0A%23%20%20%20%20%20%20%20%20%20--target-resource-group-name%20'targetRG'%0A%23%20%20%20%20%20%20%20%20%20--target-region%20'eastus'%0A%23%20%20%20%20%20%20%20%20%20--target-server-name%20'targetmysql'%0A%23%20%20%20%20%20%20%20%20%20--target-username%20'targetuser'%0A%23%20%20%20%20%20%20%20%20%20--target-password%20'P%40ssw0rd2'%0A%23%20%20%20%20%20%20%20%20%20--target-database-name%20'targetdb'%0A%23%20%20%20%20%20%20%20%20%20--target-sku%20'GP_Gen5_2'%0A%23%0A%0Afunction%20usage()%0A%7B%0A%20%20%20%20echo%20%22%22%0A%20%20%20%20echo%20%22PURPOSE%22%0A%20%20%20%20echo%20%22Migrate%20Azure%20Database%20for%20MySQL%20Server%20from%20Basic%20Pricing%20Tier%20to%20General%20Purpose%2FMemory%20Optimized%20Pricing%20Tier%22%0A%20%20%20%20echo%20%22%22%0A%20%20%20%20echo%20%22DESCRIPTION%22%0A%20%20%20%20echo%20%22Pricing%20tiers%20in%20Azure%20Database%20for%20MySQL%20-%20Single%20Server%22%0A%20%20%20%20echo%20%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fconcepts-pricing-tiers%22%0A%20%20%20%20echo%20%22%22%0A%20%20%20%20echo%20%22Currently%20modifying%20pricing%20tier%20(to%20and%20from%20Basic)%20is%20not%20yet%20supported.%22%0A%20%20%20%20echo%20%22This%20script%20helps%20in%20migrating%20an%20existing%20database%20from%20Basic%20Pricing%20Tier%20to%22%0A%20%20%20%20echo%20%22General%20Purpose%2FMemory%20Optimized%20Pricing%20Tier.%22%0A%20%20%20%20echo%20%22This%20script%20uses%20mysqldump%20to%20extract%20a%20MySQL%20database%20into%20a%20dump%20file%22%0A%20%20%20%20echo%20%22and%20mysql%20to%20restore%20the%20MySQL%20database%20from%20an%20archive%20file%20created%20by%20mysqldump.%22%0A%20%20%20%20echo%20%22%22%0A%20%20%20%20echo%20%22Migrate%20your%20MySQL%20database%20using%20dump%20and%20restore%22%0A%20%20%20%20echo%20%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fhowto-migrate-using-dump-and-restore%22%0A%20%20%20%20echo%20%22%22%0A%20%20%20%20echo%20%22PREREQUISITES%22%0A%20%20%20%20echo%20%22Azure%20CLI%20(https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Finstall-azure-cli%3Fview%3Dazure-cli-latest)%22%0A%20%20%20%20echo%20%22mysql-client%20tools%20-%20mysqldump%20and%20mysql%20(https%3A%2F%2Fdev.mysql.com%2Fdownloads%2Fmysql%2F)%22%0A%20%20%20%20echo%20%22%22%0A%20%20%20%20echo%20%22NOTE%22%0A%20%20%20%20echo%20%22Target%20server%20and%20database%20are%20created%20in%20this%20script.%22%0A%20%20%20%20echo%20%22Please%20modify%20the%20script%20to%20specify%20different%20options%20for%20server%20creation%22%0A%20%20%20%20echo%20%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Fmysql%2Fserver%3Fview%3Dazure-cli-latest%22%0A%20%20%20%20echo%20%22%22%0A%20%20%20%20echo%20%22USAGE%22%0A%20%20%20%20echo%20%22bash%20mysqlmigrate.sh%22%0A%20%20%20%20echo%20-e%20%22%5Ct--source-subscription-id%20'ffffffff-ffff-ffff-ffff-ffffffffffff'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--source-resource-group-name%20'sourceRG'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--source-server-name%20'sourcemysql'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--source-username%20'sourceuser'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--source-password%20'P%40ssw0rd1'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--source-database-name%20'sourcedb'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-subscription-id%20'ffffffff-ffff-ffff-ffff-ffffffffffff'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-resource-group-name%20'targetRG'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-region%20'eastus'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-server-name%20'targetmysql'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-username%20'targetuser'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-password%20'P%40ssw0rd2'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-database-name%20'targetdb'%22%0A%20%20%20%20echo%20-e%20%22%5Ct--target-sku%20'GP_Gen5_2'%22%0A%20%20%20%20echo%20%22%22%0A%7D%0A%0APARAMS%3D%22%22%0Awhile%20((%20%22%24%23%22%20))%3B%20do%0A%20%20case%20%22%241%22%20in%0A%20%20%20%20-h%20%7C%20--help)%0A%20%20%20%20%20%20usage%0A%20%20%20%20%20%20exit%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-a%7C--source-subscription-id)%0A%20%20%20%20%20%20SOURCE_SUBSCRIPTION_ID%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-b%7C--source-resource-group-name)%0A%20%20%20%20%20%20SOURCE_RESOURCE_GROUP_NAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-c%7C--source-server-name)%0A%20%20%20%20%20%20SOURCE_SERVER_NAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-d%7C--source-username)%0A%20%20%20%20%20%20SOURCE_USERNAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-e%7C--source-password)%0A%20%20%20%20%20%20SOURCE_PASSWORD%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-f%7C--source-database-name)%0A%20%20%20%20%20%20SOURCE_DATABASE_NAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-g%7C--target-subscription-id)%0A%20%20%20%20%20%20TARGET_SUBSCRIPTION_ID%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-h%7C--target-resource-group-name)%0A%20%20%20%20%20%20TARGET_RESOURCE_GROUP_NAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-i%7C--target-region)%0A%20%20%20%20%20%20TARGET_REGION%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-j%7C--target-server-name)%0A%20%20%20%20%20%20TARGET_SERVER_NAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-k%7C--target-username)%0A%20%20%20%20%20%20TARGET_USERNAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-l%7C--target-password)%0A%20%20%20%20%20%20TARGET_PASSWORD%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-m%7C--target-database-name)%0A%20%20%20%20%20%20TARGET_DATABASE_NAME%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-n%7C--target-sku)%0A%20%20%20%20%20%20TARGET_SKU%3D%242%0A%20%20%20%20%20%20shift%202%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20--)%20%23%20end%20argument%20parsing%0A%20%20%20%20%20%20shift%0A%20%20%20%20%20%20break%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20-*%7C--*%3D)%20%23%20unsupported%20flags%0A%20%20%20%20%20%20echo%20%22Error%3A%20Unsupported%20flag%20%241%22%20%26gt%3B%26amp%3B2%0A%20%20%20%20%20%20exit%201%0A%20%20%20%20%20%20%3B%3B%0A%20%20%20%20*)%20%23%20preserve%20positional%20arguments%0A%20%20%20%20%20%20PARAMS%3D%22%24PARAMS%20%241%22%0A%20%20%20%20%20%20shift%0A%20%20%20%20%20%20%3B%3B%0A%20%20esac%0Adone%0A%23%20set%20positional%20arguments%20in%20their%20proper%20place%0Aeval%20set%20--%20%22%24PARAMS%22%0A%0A%23%20Prerequisites%20-%20Install%20Azure%20CLI%20and%20mysql-client%20package%0Aif%20!%20%5B%20-x%20%22%24(command%20-v%20az)%22%20%5D%3B%20then%0A%20%20echo%20'Error%3A%20azure%20cli%20is%20not%20installed.%20Please%20install%20from%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Finstall-azure-cli%3Fview%3Dazure-cli-latest'%20%26gt%3B%26amp%3B2%0A%20%20exit%201%0Afi%0A%0Aif%20!%20%5B%20-x%20%22%24(command%20-v%20mysqldump)%22%20%5D%3B%20then%0A%20%20echo%20'Error%3A%20mysqldump%20command%20does%20not%20exist.%20Please%20install%20from%20https%3A%2F%2Fdev.mysql.com%2Fdownloads%2Fmysql%2F'%20%26gt%3B%26amp%3B2%0A%20%20exit%201%0Afi%0A%0Aif%20!%20%5B%20-x%20%22%24(command%20-v%20mysql)%22%20%5D%3B%20then%0A%20%20echo%20'Error%3A%20mysql%20command%20does%20not%20exist.%20Please%20install%20from%20https%3A%2F%2Fdev.mysql.com%2Fdownloads%2Fmysql%2F'%20%26gt%3B%26amp%3B2%0A%20%20exit%201%0Afi%0A%0A%23%20Login%20to%20source%20subscription%0Aaz%20login%0Aaz%20account%20set%20--subscription%20%22%24SOURCE_SUBSCRIPTION_ID%22%0A%0A%23%20Firewall%20rule%20name%20to%20allow%20the%20current%20VM%0Aexport%20FIREWALLRULENAME%3D%22AllowAllIps%24(date%20%2B%25s)%22%0A%0A%23%20Create%20firewall%20rule%20on%20the%20source%20server%20to%20allow%20connections%20from%20current%20VM%0Aaz%20mysql%20server%20firewall-rule%20create%20-g%20%22%24SOURCE_RESOURCE_GROUP_NAME%22%20-s%20%22%24SOURCE_SERVER_NAME%22%20-n%20%22%24FIREWALLRULENAME%22%20--start-ip-address%20%220.0.0.0%22%20--end-ip-address%20%22255.255.255.255%22%0A%0A%23%20Export%20mysql%20password%20to%20be%20used%20by%20the%20mysqldump%20command%0Aexport%20MYSQL_PWD%3D%24SOURCE_PASSWORD%0A%0A%23%20Remove%20dump%20file%20if%20it%20already%20exists%0A%5B%20-e%20%22%24SOURCE_DATABASE_NAME.sql%22%20%5D%20%26amp%3B%26amp%3B%20rm%20-f%20%22%24SOURCE_DATABASE_NAME.sql%22%0A%0A%23%20Create%20a%20dump%20file%20of%20the%20source%20db%0Amysqldump%20--ssl-mode%3DREQUIRED%20-Fc%20-v%20--host%3D%22%24SOURCE_SERVER_NAME.mysql.database.azure.com%22%20--user%3D%22%24SOURCE_USERNAME%40%24SOURCE_SERVER_NAME%22%20--databases%20%22%24SOURCE_DATABASE_NAME%22%20%26gt%3B%22%24SOURCE_DATABASE_NAME.sql%22%0A%0A%23%20check%20that%20filesize%20of%20dump%20file%20is%20greater%20than%200%0Aif%20!%20%5B%20-s%20%22%24SOURCE_DATABASE_NAME.sql%22%20%5D%3B%20then%0A%20%20echo%20'Error%20during%20mysqldump'%20%26gt%3B%26amp%3B2%0A%20%20exit%201%0Afi%0A%0A%23%20Login%20to%20target%20subscription%20%0Aaz%20account%20set%20--subscription%20%22%24TARGET_SUBSCRIPTION_ID%22%0A%0A%23%20Set%20target%20server%20password%0Aexport%20MYSQL_PWD%3D%24TARGET_PASSWORD%0A%0A%23%20Create%20the%20target%20server%20in%20the%20specified%20region%0Aaz%20mysql%20server%20create%20-l%20%22%24TARGET_REGION%22%20-g%20%22%24TARGET_RESOURCE_GROUP_NAME%22%20-n%20%22%24TARGET_SERVER_NAME%22%20-u%20%22%24TARGET_USERNAME%22%20-p%20%22%24MYSQL_PWD%22%20--sku-name%20%22%24TARGET_SKU%22%0A%0A%23%20Create%20the%20target%20database%0Aaz%20mysql%20db%20create%20-g%20%22%24TARGET_RESOURCE_GROUP_NAME%22%20-s%20%22%24TARGET_SERVER_NAME%22%20-n%20%22%24TARGET_DATABASE_NAME%22%0A%0A%23%20Create%20firewall%20rule%20on%20the%20target%20server%20to%20allow%20connections%20from%20current%20VM%0Aaz%20mysql%20server%20firewall-rule%20create%20-g%20%22%24TARGET_RESOURCE_GROUP_NAME%22%20-s%20%22%24TARGET_SERVER_NAME%22%20-n%20%22%24FIREWALLRULENAME%22%20--start-ip-address%20%220.0.0.0%22%20--end-ip-address%20%22255.255.255.255%22%0A%0A%23%20Export%20MYSQL%20database%20name%20to%20be%20used%20by%20the%20mysql%20command%0Aexport%20MYSQL_DATABASE%3D%24TARGET_DATABASE_NAME%0A%0A%23%20Restore%20the%20database%20using%20source%20database%20dump%20file%0Amysql%20--ssl-mode%3DREQUIRED%20-v%20--host%3D%22%24TARGET_SERVER_NAME.mysql.database.azure.com%22%20--port%3D3306%20--user%3D%22%24TARGET_USERNAME%40%24TARGET_SERVER_NAME%22%20%26lt%3B%20%22%24SOURCE_DATABASE_NAME.sql%22%0A%0A%23%20Delete%20firewall%20rules%20and%20local%20dump%20file%0Aaz%20mysql%20server%20firewall-rule%20delete%20-g%20%22%24SOURCE_RESOURCE_GROUP_NAME%22%20-s%20%22%24SOURCE_SERVER_NAME%22%20-n%20%22%24FIREWALLRULENAME%22%20--yes%0Aaz%20mysql%20server%20firewall-rule%20delete%20-g%20%22%24TARGET_RESOURCE_GROUP_NAME%22%20-s%20%22%24TARGET_SERVER_NAME%22%20-n%20%22%24FIREWALLRULENAME%22%20--yes%0Arm%20-f%20%22%24SOURCE_DATABASE_NAME.sql%22%0A%0A%23%20Logout%0Aaz%20logout%0A%0A%23%20Visit%20Target%20Server%0Aecho%20%22Migration%20Successful%20!!%22%0Aecho%20%22Target%20Server%20%3A%20https%3A%2F%2Fportal.azure.com%2F%23resource%2Fsubscriptions%2F%24TARGET_SUBSCRIPTION_ID%2FresourceGroups%2F%24TARGET_RESOURCE_GROUP_NAME%2Fproviders%2FMicrosoft.DBforMySQL%2Fservers%2F%24TARGET_SERVER_NAME%2Foverview%22%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20trouble%20running%20the%20script%2C%20please%20let%20us%20know%20by%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-mysql%2Fissues%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eopening%20an%20issue.%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EAlso%2C%20feel%20free%20to%20contribute%20any%20updates%20or%20bug%20fixes%20by%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-mysql%2Fpulls%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ecreating%20a%20pull%20request%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-830404%22%20slang%3D%22en-US%22%3E%3CP%3EUpgrade%20from%20Basic%20to%20General%20Purpose%20or%20Memory%20Optimized%20tiers%20in%20Azure%20Database%20for%20MySQL%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20225px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F129279iEF1103CCFCD41605%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22mysql.png%22%20title%3D%22mysql.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-830404%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMySQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

You can create an Azure Database for MySQL server using one of three different pricing tiers: Basic, General Purpose, and Memory Optimized. Each tier is differentiated by the amount of compute in vCores that can be provisioned, the memory per vCore, and the IOPS guaranteed.

 

You can scale a server between the General Purpose and Memory Optimized tiers. However, today there isn’t an automated way to change a server from the Basic tier to the General Purpose or Memory Optimized tiers. You can use the bash script below to simplify migrating existing databases from a Basic server to a General Purpose or Memory Optimized server.  

 

You can run the bash script from a VM (or Azure Cloud Shell). First, verify that you have installed latest version of Azure CLI and the mysql client tools mysql and mysqldump. Because MySQL utilities such as mysql/mysqldump are not necessarily forward compatible, be sure to use the same version of mysql/mysqldump as the MySQL version of the target database.

 

For the latest version of the script, please visit our GitHub repo: https://github.com/Azure/azure-mysql/blob/master/scripts/mysqlmigrate.sh

 

 

#!/bin/bash
#
# PURPOSE
# Migrate Azure Database for MySQL Server from Basic Pricing Tier to General Purpose/Memory Optimized Pricing Tier
# 
# DESCRIPTION
# Pricing tiers in Azure Database for MySQL - Single Server
# https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers
# 
# Currently modifying pricing tier (to and from Basic) is not yet supported. 
# This script helps in migrating an existing database from Basic Pricing Tier to 
# General Purpose/Memory Optimized Pricing Tier. 
# This script uses mysqldump to extract a MySQL database into a dump file
# and mysql to restore the MySQL database from an archive file created by mysqldump.
#
# Migrate your MySQL database using dump and restore
# https://docs.microsoft.com/en-us/azure/mysql/howto-migrate-using-dump-and-restore
#
# PREREQUISITES
# Azure CLI (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)
# mysql-client tools - mysqldump and mysql (https://dev.mysql.com/downloads/mysql/)
# 
# NOTE
# Target server and database are created in this script.
# Please modify the script to specify different options for creation
# https://docs.microsoft.com/en-us/cli/azure/mysql/server?view=azure-cli-latest
# 
# USAGE
# bash mysqlmigrate.sh
#         --source-subscription-id 'ffffffff-ffff-ffff-ffff-ffffffffffff'
#         --source-resource-group-name 'sourceRG'
#         --source-server-name 'sourcemysql'
#         --source-username 'sourceuser'
#         --source-password 'P@ssw0rd1'
#         --source-database-name 'sourcedb'
#         --target-subscription-id 'ffffffff-ffff-ffff-ffff-ffffffffffff'
#         --target-resource-group-name 'targetRG'
#         --target-region 'eastus'
#         --target-server-name 'targetmysql'
#         --target-username 'targetuser'
#         --target-password 'P@ssw0rd2'
#         --target-database-name 'targetdb'
#         --target-sku 'GP_Gen5_2'
#

function usage()
{
    echo ""
    echo "PURPOSE"
    echo "Migrate Azure Database for MySQL Server from Basic Pricing Tier to General Purpose/Memory Optimized Pricing Tier"
    echo ""
    echo "DESCRIPTION"
    echo "Pricing tiers in Azure Database for MySQL - Single Server"
    echo "https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers"
    echo ""
    echo "Currently modifying pricing tier (to and from Basic) is not yet supported."
    echo "This script helps in migrating an existing database from Basic Pricing Tier to"
    echo "General Purpose/Memory Optimized Pricing Tier."
    echo "This script uses mysqldump to extract a MySQL database into a dump file"
    echo "and mysql to restore the MySQL database from an archive file created by mysqldump."
    echo ""
    echo "Migrate your MySQL database using dump and restore"
    echo "https://docs.microsoft.com/en-us/azure/mysql/howto-migrate-using-dump-and-restore"
    echo ""
    echo "PREREQUISITES"
    echo "Azure CLI (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)"
    echo "mysql-client tools - mysqldump and mysql (https://dev.mysql.com/downloads/mysql/)"
    echo ""
    echo "NOTE"
    echo "Target server and database are created in this script."
    echo "Please modify the script to specify different options for server creation"
    echo "https://docs.microsoft.com/en-us/cli/azure/mysql/server?view=azure-cli-latest"
    echo ""
    echo "USAGE"
    echo "bash mysqlmigrate.sh"
    echo -e "\t--source-subscription-id 'ffffffff-ffff-ffff-ffff-ffffffffffff'"
    echo -e "\t--source-resource-group-name 'sourceRG'"
    echo -e "\t--source-server-name 'sourcemysql'"
    echo -e "\t--source-username 'sourceuser'"
    echo -e "\t--source-password 'P@ssw0rd1'"
    echo -e "\t--source-database-name 'sourcedb'"
    echo -e "\t--target-subscription-id 'ffffffff-ffff-ffff-ffff-ffffffffffff'"
    echo -e "\t--target-resource-group-name 'targetRG'"
    echo -e "\t--target-region 'eastus'"
    echo -e "\t--target-server-name 'targetmysql'"
    echo -e "\t--target-username 'targetuser'"
    echo -e "\t--target-password 'P@ssw0rd2'"
    echo -e "\t--target-database-name 'targetdb'"
    echo -e "\t--target-sku 'GP_Gen5_2'"
    echo ""
}

PARAMS=""
while (( "$#" )); do
  case "$1" in
    -h | --help)
      usage
      exit
      ;;
    -a|--source-subscription-id)
      SOURCE_SUBSCRIPTION_ID=$2
      shift 2
      ;;
    -b|--source-resource-group-name)
      SOURCE_RESOURCE_GROUP_NAME=$2
      shift 2
      ;;
    -c|--source-server-name)
      SOURCE_SERVER_NAME=$2
      shift 2
      ;;
    -d|--source-username)
      SOURCE_USERNAME=$2
      shift 2
      ;;
    -e|--source-password)
      SOURCE_PASSWORD=$2
      shift 2
      ;;
    -f|--source-database-name)
      SOURCE_DATABASE_NAME=$2
      shift 2
      ;;
    -g|--target-subscription-id)
      TARGET_SUBSCRIPTION_ID=$2
      shift 2
      ;;
    -h|--target-resource-group-name)
      TARGET_RESOURCE_GROUP_NAME=$2
      shift 2
      ;;
    -i|--target-region)
      TARGET_REGION=$2
      shift 2
      ;;
    -j|--target-server-name)
      TARGET_SERVER_NAME=$2
      shift 2
      ;;
    -k|--target-username)
      TARGET_USERNAME=$2
      shift 2
      ;;
    -l|--target-password)
      TARGET_PASSWORD=$2
      shift 2
      ;;
    -m|--target-database-name)
      TARGET_DATABASE_NAME=$2
      shift 2
      ;;
    -n|--target-sku)
      TARGET_SKU=$2
      shift 2
      ;;
    --) # end argument parsing
      shift
      break
      ;;
    -*|--*=) # unsupported flags
      echo "Error: Unsupported flag $1" >&2
      exit 1
      ;;
    *) # preserve positional arguments
      PARAMS="$PARAMS $1"
      shift
      ;;
  esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"

# Prerequisites - Install Azure CLI and mysql-client package
if ! [ -x "$(command -v az)" ]; then
  echo 'Error: azure cli is not installed. Please install from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest' >&2
  exit 1
fi

if ! [ -x "$(command -v mysqldump)" ]; then
  echo 'Error: mysqldump command does not exist. Please install from https://dev.mysql.com/downloads/mysql/' >&2
  exit 1
fi

if ! [ -x "$(command -v mysql)" ]; then
  echo 'Error: mysql command does not exist. Please install from https://dev.mysql.com/downloads/mysql/' >&2
  exit 1
fi

# Login to source subscription
az login
az account set --subscription "$SOURCE_SUBSCRIPTION_ID"

# Firewall rule name to allow the current VM
export FIREWALLRULENAME="AllowAllIps$(date +%s)"

# Create firewall rule on the source server to allow connections from current VM
az mysql server firewall-rule create -g "$SOURCE_RESOURCE_GROUP_NAME" -s "$SOURCE_SERVER_NAME" -n "$FIREWALLRULENAME" --start-ip-address "0.0.0.0" --end-ip-address "255.255.255.255"

# Export mysql password to be used by the mysqldump command
export MYSQL_PWD=$SOURCE_PASSWORD

# Remove dump file if it already exists
[ -e "$SOURCE_DATABASE_NAME.sql" ] && rm -f "$SOURCE_DATABASE_NAME.sql"

# Create a dump file of the source db
mysqldump --ssl-mode=REQUIRED -Fc -v --host="$SOURCE_SERVER_NAME.mysql.database.azure.com" --user="$SOURCE_USERNAME@$SOURCE_SERVER_NAME" --databases "$SOURCE_DATABASE_NAME" >"$SOURCE_DATABASE_NAME.sql"

# check that filesize of dump file is greater than 0
if ! [ -s "$SOURCE_DATABASE_NAME.sql" ]; then
  echo 'Error during mysqldump' >&2
  exit 1
fi

# Login to target subscription 
az account set --subscription "$TARGET_SUBSCRIPTION_ID"

# Set target server password
export MYSQL_PWD=$TARGET_PASSWORD

# Create the target server in the specified region
az mysql server create -l "$TARGET_REGION" -g "$TARGET_RESOURCE_GROUP_NAME" -n "$TARGET_SERVER_NAME" -u "$TARGET_USERNAME" -p "$MYSQL_PWD" --sku-name "$TARGET_SKU"

# Create the target database
az mysql db create -g "$TARGET_RESOURCE_GROUP_NAME" -s "$TARGET_SERVER_NAME" -n "$TARGET_DATABASE_NAME"

# Create firewall rule on the target server to allow connections from current VM
az mysql server firewall-rule create -g "$TARGET_RESOURCE_GROUP_NAME" -s "$TARGET_SERVER_NAME" -n "$FIREWALLRULENAME" --start-ip-address "0.0.0.0" --end-ip-address "255.255.255.255"

# Export MYSQL database name to be used by the mysql command
export MYSQL_DATABASE=$TARGET_DATABASE_NAME

# Restore the database using source database dump file
mysql --ssl-mode=REQUIRED -v --host="$TARGET_SERVER_NAME.mysql.database.azure.com" --port=3306 --user="$TARGET_USERNAME@$TARGET_SERVER_NAME" < "$SOURCE_DATABASE_NAME.sql"

# Delete firewall rules and local dump file
az mysql server firewall-rule delete -g "$SOURCE_RESOURCE_GROUP_NAME" -s "$SOURCE_SERVER_NAME" -n "$FIREWALLRULENAME" --yes
az mysql server firewall-rule delete -g "$TARGET_RESOURCE_GROUP_NAME" -s "$TARGET_SERVER_NAME" -n "$FIREWALLRULENAME" --yes
rm -f "$SOURCE_DATABASE_NAME.sql"

# Logout
az logout

# Visit Target Server
echo "Migration Successful !!"
echo "Target Server : https://portal.azure.com/#resource/subscriptions/$TARGET_SUBSCRIPTION_ID/resourceGroups/$TARGET_RESOURCE_GROUP_NAME/providers/Microsoft.DBforMySQL/servers/$TARGET_SERVER_NAME/overview"

 

If you have trouble running the script, please let us know by opening an issue.

Also, feel free to contribute any updates or bug fixes by creating a pull request.

 

Thank you!