So here is source code. I write one query to check connection.
If you want to see more details about mysql.connector module. Please check this link.
import mysql.connector
from mysql.connector import (connection)
try :
mydb = mysql.connector.connect(
host="localhost",
user="testuser",
password="0000",
auth_plugin='mysql_native_password'
)
# simple query to check mysql is connected.
# list tables from world database
sql_select_Query = "show tables from world"
cursor = mydb.cursor()
cursor.execute(sql_select_Query)
records = cursor.fetchall()
print('tables : ', records)
# close mysql connection
if mydb.is_connected():
cursor.close()
mydb.close()
print("MySQL connection is closed")
except mysql.connector.Error as e:
print("Error reading data from MySQL table", e)
If connection is success, you can see this result.
If connection is not worked, you can see error message. You can see one of error message below.
ERROR 1045 is one of error value When you enter an incorrect password or password for your database.
We also need to install a compiler. C++ is a compiled language so we must complie before it can be run in your machine. Unfortunately, VS code is an editor and does not include a C++ compiler or debugger. Therefore, you need to install a compiler additionally.
But, maybe you already have a compiler. Check if you have a compiler.
Please open Command Prompt in your machine and write this command.
This command is to check for the GCC compiler:
g++ --version
If you can see g++ version like below, you have already a compiler.
If you don't have any compiler, I recommend to you to install MinGW-x64 via MSYS2. The MSYS2 link is here(MSYS2)
If you install all toolchain, now you need to add the MinGW compiler to your environment PATH.
Please follow these steps.
1. open Windows settings.
2. search for Edit environment variables for your account.
3. Choose the Path variable in your User variables and then select Edit.
4. add your mingw-w64 installed path into Path. If you don't change any installation path, it should be C:\msys64\mingw64\bin.
5. Select OK.
Now, we can check your MinGW compiler.
Please open Command Prompt in your machine and write this command.
gcc --version
g++ --version
gdb --version
If you can see all version, you succeed to install MinGW.
But if you cannot see all, please check your PATHcorrect and C:\msys64\mingw64\bin folder has files. If you don't have files in C:\msys64\mingw64\bin folder, you need to install full Mingw-w64 toolchain again.
3. Run Hello World
So now, we need to check the compiler is working fine.
Let's open VS code and create a folder HelloWord and create helloworld.cpp file.
I just created one more parent folder "C++". But it doesn't matter!
Now, please paste this script into your source code(helloworld.cpp) and save source code: