Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Monday, July 9, 2012

How to import a MySQL dump file into a Database

To import MySQL dump file into a database you must have a MySQL command line shell.

Step #1: Make sure your database is already created. If database is not created yet, then you have to create one database. For example:

->mysql -h localhost -u root -p;
(enter your password)
->CREATE SCHEMA IF NOT EXISTS 'database_name';
->exit;

Note

You can replace "localhost" by an IP address (e.g. 192.168.1.88).

Step #2: Type the next command to import MySQL dump file into a database.

->mysql -h localhost -u root -p database_name < file.sql
(enter your password)

Voilá! Now you have a database with all data filled.

Tuesday, May 1, 2012

How to install Oracle Database Express Edition


I heard talk about technology Oracle PL/SQL but I never tried it. To study PL/SQL it is necessary install software Oracle Database 11g Express Edition. Hereafter you have 3 minutes video showing all necessary steps to installation correct.

Monday, April 9, 2012

What is Data Warehouse?

Definition #1
A data warehouse is a system that retrieves and consolidates data periodically from the source systems into a dimensional or normalized data store. 


Definition #2
A Data Warehouse is a database that is designed for facilitating querying and analysis. These database contain read-only data that can be queried and analysed.


Conclusion:
So what is difference between database and data warehouse?
Database is designed to record data and Data Warehouse is designed to analysis data.

Monday, October 31, 2011

Convert dates in PHP and MySQL

Today I was working in project and I was confronted by one problem. As I live in Europe, the date's format are not the same in United States even MySQL. US use mm/dd/yyyy format, Europe use dd/mm/yyyy and MySQL use yyyy-mm-dd.


After I researched on PHP and MySQL official sites, I wrote algorithms that allowed me insert correctly data in SQL. 


PHP to MySQL:


SQL:


create schema test;


create tabela xpto(
id int not null auto_increment,
start_date date,
end_date date,
primary key(id)
)engine=innodb;




PHP:
<?php
$start_date = "10/10/2011";
$end_date = "12/10/2011";


$query0 = "select str_to_date('$start_date','%d/%m/%Y')";
$result0 = mysql_query($query0) or die(mysql_error());
$row0 = mysql_fetch_array($result0);


$query1 = "select str_to_date('$end_date','%d/%m/%Y')";
$result1 = mysql_query($query1) or die(mysql_error());
$row1 = mysql_fetch_array($result1);


$query2 = "insert into xpto (start_date, end_date) values ('".$row0[0]."','".$row1[0]."')";
$result2 = mysql_query($query2) or die(mysql_error());
?>


To check out the data inserted, type on mysql terminal:
select * from xpto;


MySQL to PHP:
It is enough select data stored and use two functions to show date format correctly.




PHP:
<?php
mysql_connect("localhost","user","pass") or die (mysql_error());
mysql_select_db("test");


$query0="select start_date from xpto where id=1";
$result0 = mysql_query($query0) or die (mysql_error());
$row0 = mysql_fetch_array($result0,MYSQL_NUM);



$query1="select end_date from xpto where id=1";
$result1 = mysql_query($query1) or die (mysql_error());
$row1 = mysql_fetch_array($result1,MYSQL_NUM);


$start_date=$row0[0];//"2011-10-10"
$end_date=$row1[0];//"2011-10-12"


$d0 = strtotime($start_date);
$d1 = date('d/m/Y',$d0);
echo $d1."<br />";


$d2 = strtotime($end_date);
$d3 = date('d/m/Y',$d2);
echo $d3."<br />";
?>


Happy Halloween! :)

Thursday, April 21, 2011

How to backup data with phpMyAdmin

Today, in my project, I need to back up because of an unforeseen event. But I do not want to do it manually because it takes a long time. I wanted to do it automatically.  
I found out how to do backup with phpmyadmin automatically. Click this link to see how.