Attach a sql database running SQL Server on EC2

Dec 15, 2020    Janaki Mahapatra, Installation

Here are the steps to attach a SQL db 

  1. Copy the database data and log files to /var/opt/mssql/data
  2. Run chmod 777 for the data and log file
  3. Connect to Sql Server using sqlcmd command line: sqlcmd -S localhost -U sa
  4. Run the attach T-SQL script:
CREATE DATABASE [db_name] ON PRIMARY (FILENAME=N'/var/opt/mssql/data/your_db_Data.mdf') 
LOG ON (FILENAME=N'/var/opt/mssql/data/your_db_Log.ldf') FOR ATTACH;