SQL Server Command-Line Installation
This guide provides detailed instructions for installing SQL Server using the command line. This method is particularly useful for unattended installations, scripting, and automation.
Overview of Command-Line Installation
The command-line installation process for SQL Server leverages the setup executable (setup.exe) with specific parameters. You can control various aspects of the installation, including instance name, features to install, collation settings, and more.
Steps for Command-Line Installation
1. Prepare Installation Media
Download the SQL Server installation media (ISO file or extracted files) from the official Microsoft website.
2. Open Command Prompt or PowerShell
Launch Command Prompt or PowerShell as an administrator. Right-click on the application icon and select "Run as administrator".
3. Navigate to the Installation Directory
Use the cd command to navigate to the directory where the SQL Server setup files are located. For example:
cd D:\SQLServer2022\x64
4. Run the Setup Command
Execute the setup.exe command with the required parameters. Here's a basic example for installing a default instance with specific features:
setup.exe /ACTION=Install /FEATURES=SQLENGINE,SSMS /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT="\" /SQLSVCPASSWORD="" /AGTSVCACCOUNT="\" /AGTSVCPASSWORD="" /IACCEPTSQLSERVERLICENSEAGREEMENTS
Common Installation Parameters
/ACTION: Specifies the action to perform. Common values areInstall,Upgrade,Uninstall./FEATURES: Comma-separated list of features to install. Examples:SQLENGINE(Database Engine),SSMS(SQL Server Management Studio),REPLICATION,ISSERVICERVICES./INSTANCENAME: The name of the SQL Server instance. UseMSSQLSERVERfor the default instance./SQLSVCACCOUNT: The account name for the SQL Server service./SQLSVCPASSWORD: The password for the SQL Server service account./AGTSVCACCOUNT: The account name for the SQL Server Agent service./AGTSVCPASSWORD: The password for the SQL Server Agent service account./DATADIR: Specifies the directory for database files./LOGDIR: Specifies the directory for setup log files./IACCEPTSQLSERVERLICENSEAGREEMENTS: Required to accept the license terms.
setup.exe /? in the command prompt.
Example: Installing a Named Instance
To install a named instance, specify a custom /INSTANCENAME:
setup.exe /ACTION=Install /FEATURES=SQLENGINE /INSTANCENAME=MyNamedInstance /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /IACCEPTSQLSERVERLICENSEAGREEMENTS
Example: Installing with a Configuration File
You can also use a configuration file (ConfigurationFile.ini) for complex installations. First, generate a sample configuration file by running:
setup.exe /PCConfigurationFile="C:\MyConfig\ConfigurationFile.ini"
Then, modify the generated INI file with your desired settings and run the installation using:
setup.exe /ConfigurationFile="C:\MyConfig\ConfigurationFile.ini"
Configuration File Example (ConfigurationFile.ini)
[OPTIONS]
ACTION="Install"
FEATURES=SQLENGINE,CONN,BC,SDK,SSMS
INSTANCENAME="MYNEWINSTANCE"
SQLSVCACCOUNT="NT AUTHORITY\Network Service"
ISSVCSTARTUPTYPE="Automatic"
SQLCOLLATION="SQL_Latin1_General_CP1_CI_AS"
AGTSVCACCOUNT="NT AUTHORITY\Network Service"
AGTSVCSTARTUPTYPE="Automatic"
IACCEPTSQLSERVERLICENSEAGREEMENTS="True"
TCPENABLED="1"
NPENABLED="0"
SQLSVCINSTANCENAME="MYNEWINSTANCE"
AGTSVCINSTANCENAME="MYNEWINSTANCE"
Verification
After the installation completes, you can verify it by checking the SQL Server services in the Services snap-in (services.msc) and connecting to the instance using SQL Server Management Studio (SSMS).
Troubleshooting
Setup log files are located in the %ProgramFiles%\Microsoft SQL Server\ directory. Review these logs for detailed error information.
IACCEPTSQLSERVERLICENSEAGREEMENTS parameter is set to True.