MySQL
This section provides an overview of using MySQL.
We will create a Local MySQL Database. This will be used in CSCN-326.
Create a Local MySQL Database
Pre-requisites
Steps
-
Open a terminal and run the following command to pull the latest SQL Server image from Docker Hub
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=VeryStr0ngP@ssw0rd -d mysql:latest
-
Check Docker to make sure the container is running
Connecting to the Local MySQL Database
- Open Azure Data Studio and click
New Connection
- Change
Connection Type
toMySQL
- Enter
localhost
intoServer
- Enter
root
intoUser name
- Enter
VeryStr0ngP@ssw0rd
intoPassword
- Click
Remember Password
- Click
Advanced
- Enter
3306
intoPort
- Click
Connect
Username: root
Password: VeryStr0ngP@ssw0rd
You should now be connected to your Local MySQL Database.
From here, you can create a new database, create tables, and run queries. We recommend looking at the Azure Data Studio Documentation to learn more about Azure Data Studio.
MySQL CLI Development
Install MySQL CLI
If you are using a Mac, you can install MySQL CLI by using the following command:
brew install mysql
Connect to Local MySQL Database by CLI
Open a terminal window and connect to your Local MySQL Database server using the following command:
mysql -h localhost -u root -p [DATABASE_NAME]
You will be prompted to enter your password.
Enter password:
Enter the password you used when you created the server.
Now, you are connected to your Local MySQL Database.
Run MySQL Scripts by CLI
To run MySQL scripts by CLI, you can use the following command:
mysql -h localhost -u root -p [DATABASE_NAME] < [SCRIPT_NAME].sql
You will be prompted to enter your password.
Enter password:
Enter the password you used when you created the server.
Now, your script will be executed, and you will see the results in the terminal window.
MySQL & PHP Development
Pre-requisites
- 5 Server VSCode Extension
- Docker
- Docker MySQL Setup
Connection String for MySQL
$connection = mysqli_connect('localhost:3306', 'root', 'VeryStr0ngP@ssw0rd', 'Labs')
Run PHP Scripts
- Open the PHP file you want to run in VSCode
- Click the
Go Live
button in the bottom right corner of the window