MySQL
How to import large csv file to mysql database in seconds
I had faced a troublesome situation while working with SUST automated mobile based admission registration system. The scene was that, Bangladesh education board give us their database of 1 million students personal info and academic results in old MS Foxpro format. It is single file with more than 1 gb in size. It was really causing so much trouble to convert it into mysql database until i reach the solution below. Before finding it we were trying to parse all that 1gb file into sql query using java. In a P4 computer it took nearly 4/5hrs to parse arrount 20K entries as java heap memory was continiously exceeding limit.
No CommentsBackup mysql database using php
When working with the library automation system of our university, we had to develop a system to backup database to sql file. After searchin in the net for a while we found two solution one is using exec to call mysqldump and generate the output file.
But we found another simple php script which will also generate sql output from database. Here is the code.
No CommentsHow to connect to mysql database using ANSI C language
This is a sample program which connect to mysql database using in c programming.
#include<stdio.h>
#include<mysql/mysql.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server ="localhost";
char *user = "root";
char *password = "123456";
char *database = "dsc";
conn = mysql_init(NULL);
// Connect to database
if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
// sql query
if(mysql_query(conn, "select * from dsc_scripts"))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
//output table name
printf("Mysql Tables in mysql database: \n");
while((row = mysql_fetch_row(res)) !=NULL)
printf("%-3s%-30s%-30s\n", row[0], row[1], row[2]);
// close connection
mysql_free_result(res);
mysql_close(conn);
return 0;
}
No CommentsFind rows within a day interval in mysql
Suppose you have a table where is a datetime or timestamp column that holds create date of row.
Now you want to find the rows that were added within last 7 days. What is the solution ??
Date_SUB is the solution!
Using mysql date_sub function you can solve this issue.
No CommentsConnect to mysql database using C#
I searched Internet a lot before I could figure out how to connect to mysql database server using C#. This is the one that worked in my favour.
To connect to mysql database using C# first you should have to download a small program called mysql connector .net from MySQL’s official site. Click here to visit this link to download mysql connector .net
6 Comments