-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql-install.ps
53 lines (42 loc) · 2.07 KB
/
mysql-install.ps
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
netsh winhttp set proxy "16.85.88.10:8080"
$mySqlRoot = "C:\ProgramFiles\MySQL"
$mySqlPath = "C:\ProgramFiles\MySQL\MySQL_Server_5.7"
$mySqlIniPath = "$mySqlPath\my.ini"
$mySqlDataPath = "$mySqlPath\data"
$mySqlTemp = "C:\Users\Administrator\Downloads"
$mySqlServiceName = "MySQL57"
$mySqlRootPassword = 'Password12!'
$url = 'https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-winx64.zip'
Write-Host "Installing MySQL Server 5.7" -ForegroundColor Cyan
Write-Host "Downloading MySQL..."
$zipPath = "$mySqlTemp\$(Split-Path -Path $url -Leaf)"
echo $zipPath
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
$webproxy = New-Object System.Net.WebProxy("http://16.85.88.10:8080",$true)
$web = New-Object System.Net.WebClient
$web.Proxy = $webproxy
$web.DownloadFile($url, $zipPath)
Write-Host "Unpacking..."
New-Item $mySqlRoot -ItemType Directory -Force | Out-Null
New-Item $mySqlPath -ItemType Directory -Force | Out-Null
$ExtractShell = New-Object -ComObject Shell.Application
$Files = $ExtractShell.Namespace($zipPath).Items()
$ExtractShell.NameSpace($mySqlPath).CopyHere($Files)
Write-Host "Installing MySQL..."
New-Item $mySqlDataPath -ItemType Directory -Force | Out-Null
@"
[mysqld]
basedir=$($mySqlPath.Replace("\","\\"))
datadir=$($mySqlDataPath.Replace("\","\\"))
"@ | Out-File $mySqlIniPath -Force -Encoding ASCII
Write-Host "Initializing MySQL..."
cmd /c '"$mySqlPath\mysql-5.7.27-winx64\bin\mysqld" --defaults-file="$mySqlIniPath" --initialize-insecure'
Write-Host "Installing MySQL as a service..."
cmd /c '"$mySqlPath\mysql-5.7.27-winx64\bin\mysqld" --install $mySqlServiceName"'
Start-Service $mySqlServiceName
Set-Service -Name $mySqlServiceName -StartupType Manual
Write-Host "Setting root password..."
cmd /c "`"$mySqlPath\mysql-5.7.27-winx64\bin\mysql`" -u root --skip-password -e `"ALTER USER 'root'@'localhost' IDENTIFIED BY '$mySqlRootPassword';`""
Write-Host "Verifying connection..."
(cmd /c '"$mySqlPath\mysql-5.7.27-winx64\bin\mysql" -u root --password="$mySqlRootPassword" -e "SHOW DATABASES;" 2>&1')
Write-Host "MySQL Server installed" -ForegroundColor Green