This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
7-create-mysql.ps1
72 lines (63 loc) · 2.29 KB
/
7-create-mysql.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Install Azure PowerShell module (needs admin privilege)
Install-Module -Name Az -AllowClobber
# Variables to edit
$YOURSUBSCRIPTIONID='XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
$RESOURCEGROUPNAME='myResourceGroup'
$REGIONNAME='japanwest'
$PREFIX='myGameBackend'
$RANDOMNUMBER=Get-Random
$MYSQLNAME=$PREFIX+'MySQL'
$MYSQLNAMELOWER=$MYSQLNAME.tolower()
$MYSQLNAMEUNIQUE=$MYSQLNAMELOWER+$RANDOMNUMBER
$MYSQLUSERNAME='azuremysqluser'
$MYSQLPASSWORD='CHang3thisP4Ssw0rD'
$MYSQLDBNAME='gamedb'
$MYSQLBACKUPRETAINEDDAYS=7
$MYSQLGEOREDUNDANTBACKUP='Disabled'
$MYSQLSKU='GP_Gen5_2'
$MYSQLSTORAGEMBSIZE=51200
$MYSQLVERSION='5.7'
$MYSQLREADREPLICANAME=$MYSQLNAMEUNIQUE+'Replica'
$MYSQLREADREPLICAREGION='westus'
$MYSQLSUBNETNAME=$MYSQLNAME+'Subnet'
$MYSQLSUBNETADDRESSPREFIX='10.0.2.0/24'
$MYSQLRULENAME=$MYSQLNAME+'Rule'
# Connect to Azure
Connect-AzAccount
# Set the Azure subscription
Set-AzContext `
-SubscriptionId $YOURSUBSCRIPTIONID
# Create the server, database and other routinely tasks
$storageProfileVariable = @{
"storageMB"=$MYSQLSTORAGEMBSIZE;
"backupRetentionDays"=$MYSQLBACKUPRETAINEDDAYS;
"geoRedundantBackup"=$MYSQLGEOREDUNDANTBACKUP
}
New-AzResource `
-ResourceGroupName $RESOURCEGROUPNAME `
-ResourceType "Microsoft.DBforMySQL/servers" `
-ResourceName $MYSQLNAMEUNIQUE `
-ApiVersion 2017-12-01 `
-Location $REGIONNAME `
-SkuObject @{name=$MYSQLSKU} `
-PropertyObject @{version = $MYSQLVERSION; administratorLogin = $MYSQLUSERNAME; administratorLoginPassword = $MYSQLPASSWORD; storageProfile=$storageProfileVariable} `
New-AzResource `
-ResourceGroupName $RESOURCEGROUPNAME `
-ResourceType "Microsoft.DBforMySQL/servers/firewallRules" `
-ResourceName $MYSQLNAMEUNIQUE/rule1 `
-ApiVersion 2017-12-01 `
-PropertyObject @{startIpAddress="0.0.0.0"; endIpAddress="255.255.255.255"}
New-AzResource `
-ResourceGroupName $RESOURCEGROUPNAME `
-ResourceType "Microsoft.DBforMySQL/servers/databases" `
-ResourceName $MYSQLNAMEUNIQUE/$MYSQLDBNAME `
-ApiVersion 2017-12-01 `
-PropertyObject @{collation='utf8_general_ci'; charset='utf8'}
Set-AzResource `
-ResourceGroupName $RESOURCEGROUPNAME `
-ResourceType "Microsoft.DBforMySQL/servers" `
-ResourceName $MYSQLNAMEUNIQUE `
-ApiVersion 2017-12-01 `
-PropertyObject @{allowAzureServices='true'} `
-Resources @{allowAzureServices='true'} `
-UsePatchSemantics