In this lab, you create database servers running on Compute Engine. You create both Linux and Windows servers and use the CLI to automate the creation of a server.
In this task, you use Qwiklabs and perform initialization steps for your lab.
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
- 
Open a new web browser window and navigate to the Google Cloud Console (console.cloud.google.com). Use the project selector to choose
the first project with a leading name of 'qwiklabs-gcp.' 
- 
On the Navigation menu ( ), click Compute Engine > VM instances. ), click Compute Engine > VM instances.
 
- 
To create a new instance, click Create Instance. 
- 
On the Machine configuration page, specify the following values: 
| Field | Value |  
| Name | mysql-db |  
| Region |  |  
| Zone |  |  
 
- 
Click OS and storage. Click Change to begin configuring your boot disk and select the values for: 
- 
Operating system: Debian
- 
Version: Debian GNU/Linux 12 (bookworm)
 Leave the size as default and Click on Select. 
- 
Accept the remaining defaults, and then click Create. 
- 
When the VM is ready, click SSH. 
 
 This will log you in to the server in a new tab.  
 
- 
In the terminal window, to update the packages and install MySQL using the apt-get package manager, enter the following command: sudo apt-get update
sudo apt-get install -y default-mysql-server
- 
To secure the database, enter the following command: sudo mysql_secure_installation
- 
When you are prompted for the current password for root, press Enter (Return) for none. 
- 
When you are prompted for Switch to unix_socket authentication [Y/n], press N. 
- 
When you are prompted for Change the root password?  [Y/n],  press Y. Enter something you will remember, because you will need it later. 
- 
When you are prompted for Remove anonymous users? [Y/n], press N. 
- 
When you are prompted for Disallow root login remotely? [Y/n], press N. 
- 
When you are prompted for Remove test database and access to it? [Y/n], press N. 
- 
When you are prompted for Reload privilege tables now? [Y/n], press Y. 
- 
Now log in to the database. Enter the following command, and then enter your password when prompted: sudo mysql -u root -p
- 
At the MariaDB [(none)]>prompt, to see the current databases, enter the following command:
 SHOW databases;
- 
To create a new database, enter the following command: CREATE database petsdb;
- 
Switch to that database: USE petsdb;
- 
Create a table: CREATE TABLE pets (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255),
    breed VARCHAR(255)
);
- 
Add a record: INSERT INTO pets (name, breed)
VALUES ('Noir', 'Schnoodle');
- 
Confirm that your record was added: SELECT * FROM pets;
- 
Type exit to log out of the database. 
- 
Type exit again to close the SSH session. 
You just created a MySQL database server using Debian Linux.
- 
Return to the Google Cloud Console and the Compute Engine service. 
- 
To create a new instance, click Create Instance. 
- 
On the Machine configuration page, specify the following values: 
| Field | Value |  
| Name | sql-server-db |  
| Region |  |  
| Zone |  |  
| Series | E2 |  
| Machine Type | e2-standard-4 |  
 
- 
Click OS and storage. Click Change to begin configuring your boot disk and select the following values: 
- 
Operating system: SQL Server on Windows Server
- 
Version: SQL Server 2019 Web on Windows Server 2019 Datacenter
 Leave the size as default and Click on Select. 
- 
Accept the remaining defaults, and then click Create. 
- 
When the Windows server is ready, click the dropdown arrow in the Connect column, and then select Set Windows password.  
 Note: If you get to this point too quickly, the Windows server may not be ready, even though a green check in the console indicates that it is. Wait a couple of minutes and try again.
- 
Leave the Username as it is (the generated username is a portion of your Qwiklabs username), and then click Set. 
- 
Copy and paste the generated password into a text file so you don't lose it, and then click Close. You need to have an RDP client to log on to the Windows machine. 
- 
Do one of the following: 
- If you are using Windows, you already have RDP:
- Click the dropdown arrow in the Connect column, and then select Download the RDP file.
- When the download is complete,  double-click the file and then log in with your username and the password you copied.
 
- If you are using a Mac:
- Install the Microsoft Remote Desktop client from the Apple App Store (you may already have it installed).
- After you install the client, download the RDP file, and then log in with your username and the password you copied.
 
 
- 
When you are logged on to the Windows server, close the Server Manager Dashboard. 
- 
On the Start menu, type SSMS, then right click the SQL Server Management Studio shortcut, and choose Run as administrator to run the program. 
- 
On the Popup window choose Yes when prompted Do you want to allow this app to make changes to your device?. 
- 
In the Connect to Server dialog, the server name should be SQL-SERVER-DB. 
- 
Check the Trust server certificate and click Connect. 
- 
In Management Studio, in the Object Explorer, right-click SQL-SERVER-DB, and select Properties. 
- 
In the Server Properties dialog, select the Security page. 
- 
For Server Authentication, select SQL Server and Windows Authentication mode, and then click OK. 
- 
Read the warning message and click OK again. 
- 
In Object Explorer, right-click the SQL-SERVER-DB server, and select Restart. 
- 
Click Yes when prompted. If the Restart command is disabled, click the Start menu and reboot the server. Give it a minute or two and then restart your RDP session. 
- 
When you're logged in, return to SQL Server Management Studio and Run as administrator and connect to the database server. 
- 
Expand the Security and Logins branch of the tree view. Right-click on the Logins branch, and select New Login. 
- 
For Login name, enter your first name or another unique value. 
- 
Select SQL Server authentication. 
- 
Enter a password you will remember (paste it in a text file if you like). 
- 
Clear Enforce password policy. a. Click the Server roles page, and select the sysadmin role. b. Click the User Mapping page, and select all the databases. c. Click OK. 
- 
To test the login you just created, in Object Explorer, click Connect, and then select Database Engine. 
- 
For Authentication, select SQL Server Authentication. 
- 
Enter your login and password, then check Trust server certificate. Click Connect. 
- 
In the toolbar, click New Query. 
- 
To create a database, enter the following command, and then click Execute: CREATE DATABASE petsdb;
- 
In the databases dropdown to the left of the Execute button, select your petsdbdatabase.
 
- 
To create a table, enter the following command, and then click Execute: USE petsdb;
CREATE TABLE pets (
    id INT PRIMARY KEY IDENTITY (1, 1),
    name VARCHAR (MAX),
    breed VARCHAR (MAX)
);
- 
To add a record: INSERT INTO pets (name, breed)
VALUES ('Noir', 'Schnoodle');
- 
To confirm that it worked: SELECT * FROM pets;
- 
Close your RDP connection. 
You just created a SQL Server database server running on Windows.
- 
Return to the Google Cloud Console and the Compute Engine service. 
- 
To create a new instance, click CREATE INSTANCE. 
- 
On the Machine configuration page, specify the following values: 
| Field | Value |  
| Name | db-server |  
| Region |  |  
| Zone |  |  
 
- 
Click OS and storage. Click Change to begin configuring your boot disk and select the following values: 
- 
Version: Debian GNU/Linux 12 (bookworm)
 Leave the size as default and Click on Select. 
- 
Click Observability 
- Uncheck the Install Ops Agent for Monitoring and Logging under Ops Agent (Recommended).
 
- 
Click Advanced then in Automation - Startup script paste the following: #! /bin/bash
sudo apt-get update
sudo apt-get install -y default-mysql-server
- 
Scroll to the bottom, but do not click the Create button; instead click the Equivalent Code button on the top right and then navigate to the  Command Line pane on the right of the screen. This pane shows you the gcloud CLI command you can use to automate this server's creation as you configured it. Next, make a small change to this command. 
- 
Click Copy at the bottom of the pane. 
- 
Cancel the Create an instance wizard. 
- 
In Notepad or similar text editor, paste the copied code. 
- 
If present, from the list of commands remove the following parameter: --provisioning-model=STANDARD Note: Please be careful to only delete the provisioning-model parameter.
- 
Select the entire edited command and copy it to the clipboard. 
- 
Launch the Cloud Shell in the top right section of the Cloud Console page, paste the command, and press Return/Enter to create the VM. If prompted, click Authorize. 
- 
Press Return (Enter) to allow for an empty passphrase. 
- 
Please wait for 3 to 5 minutes for the startup script to run.  Then in the Cloud Shell terminal, enter the following to log in to the virtual machine: gcloud compute ssh db-server --zone={{{project_0.default_zone | ZONE}}}
- 
If asked: Do you want to continue(Y/n)?, Enter Y.  Accept all defaults for setting up secure communications. 
- 
To see whether your database server is running, enter the following command: sudo systemctl status mysqlThe output on the console should contain a row similar to the following: Aug 17 14:32:10 db-server systemd[1]: Started MariaDB 10.5.15 database server.
- 
Press Q to exit the status screen. 
You created database servers running on Compute Engine. You created both Linux and Windows servers and have used the CLI to automate the creation of a server.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
You can close the dialog box if you don't want to provide feedback.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.