Wednesday, April 26, 2023

Get all column names in MySQL of a table comma separated

 For that you can use the following MySQL: 


select group_concat(column_name order by ordinal_position) from information_schema.columns where table_schema = 'vops' and table_name = 'vmdata'

Thursday, April 6, 2023

How to check the final SQL query generated by Entity Framework based on the LINQ expression for MySQL database

 If you want to check the final SQL query generated by  Entity Framework based on the LINQ expression for MySQL database  . you can follow the following steps : 


1. Connect to your MySQL command line 

2. run the following command :  SET GLOBAL general_log = 'ON';

3. In next command you need to setup the log file location. Here is the command for that SET GLOBAL general_log_file = 'C://file.log';

4. Execute the method for which you want to check the SQL query. 

5. Once you are done SET GLOBAL general_log = 'OFF'; run this. 

You can now check in your log file the output sql query from Entity Framework . 


Wednesday, March 29, 2023

Server sent charset unknown to the client.

 After install mysql 8. I'm trying to connect to a MySQL database from php. 


<?php

echo "Hello World!";

?>


</br>

<?php

$link = mysqli_connect('localhost', 'root', 'pass12#####');

if (!$link) {

echo "Failed to connect to MySQL: " . mysqli_connect_error();

die('Could not connect: ' . mysqli_error());

}

echo 'Connected successfully';

mysqli_close($link);

?>


</br>

<?php

phpinfo();

?>

</br>

But when I put in username and password I get the error message saying:


Server sent charset unknown to the client. Please, report to the developers

Solution

MySQL 8 changed the default charset to utf8mb4. But some clients don't know this charset. Hence when the server reports its default charset to the client, and the client doesn't know what the server means, it throws this error.


Edit my.cnf, specify the client code, and add the following content.


[client]

default-character-set=utf8


[mysql]

default-character-set=utf8


[mysqld]

collation-server = utf8_unicode_ci

character-set-server = utf8


Wednesday, January 18, 2023

How to find the data directory path in MySQL from command line

 show variables like 'datadir';

MYSQL 5.6 data directory in windows

 DB file location in mysql 5.6 in windows 

The default data directory location is C:\Program Files\MySQL\MySQL Server 5.6\data , or C:\ProgramData\Mysql on Windows 7 and Windows Server 2008. The C:\ProgramData directory is hidden by default.

Wednesday, January 4, 2023

Create a object of class in c# from string input dynamically from user

 You can use the following code to create object from a class which name is provided by the user in program run time. 


Type type = Type.GetType("Employee");

object instance = Activator.CreateInstance(type);


just for reference sharing the URL of the static class Activator which is part of system namespace. 


https://learn.microsoft.com/en-us/dotnet/api/system.activator?view=net-7.0

Tuesday, January 3, 2023

python code to import xlsx file in mysql and validate also each column and rows before import

 import mysql.connector

import openpyxl


# Open the .xlsx file

wb = openpyxl.load_workbook('data.xlsx')

sheet = wb.active


# Connect to the MySQL database

cnx = mysql.connector.connect(user='user', password='password', host='host', database='database')

cursor = cnx.cursor()


# Validate and import the data

for row in sheet.rows:

    # Validate each cell in the row

    if row[0].value == None:

        print("Error: Missing value in column 1")

    elif row[1].value == None:

        print("Error: Missing value in column 2")

    else:

        # If the data is valid, insert it into the database

        sql = "INSERT INTO table (column1, column2) VALUES (%s, %s)"

        val = (row[0].value, row[1].value)

        cursor.execute(sql, val)


# Commit the changes to the database

cnx.commit()


# Close the connection

cnx.close()

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...