Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.03 sec)
kodingwindow@kw:~/csharp$
C# program to create a database in MySQL
Program.cs
usingMySql.Data.MySqlClient;usingSystem;namespaceKodingwindow{classProgram{publicstaticvoidMain(string[]args){stringdbname="DB";MySqlConnectioncon=newMySqlConnection("server=localhost;user=root;port=3306;password=passwd");MySqlCommandcmd;try{con.Open();Console.WriteLine("Connection Established Successfully");cmd=newMySqlCommand("DROP DATABASE IF EXISTS "+dbname+"",con);cmd.ExecuteNonQuery();cmd=newMySqlCommand("CREATE DATABASE "+dbname+"",con);cmd.ExecuteNonQuery();Console.WriteLine("Database Created");Console.WriteLine("\nList of MySQL Databases: ");cmd=newMySqlCommand("SHOW DATABASES",con);MySqlDataReaderdr=cmd.ExecuteReader();while(dr.Read()){Console.WriteLine(dr[0]);}dr.Close();con.Close();Console.WriteLine("\nConnection Released Successfully");}catch(Exceptione){Console.WriteLine(e.Message);}Console.ReadKey();}}}
Output
Connection Established Successfully
Database Created
List of MySQL Databases:
db
information_schema
mysql
performance_schema
sys
Connection Released Successfully
MySQL Instance
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| db |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?