How to load data from file into table

If you want to load data into a table from a local file, do as follow:

load data local infile ” into table table_name fields terminated by ” lines terminated by ”;

example:

load data local infile ‘/input/data’ into table TEMPLATE fields terminated by ‘,’ lines terminated by ‘\n’;

Comments Off on How to load data from file into table Posted in Database, MySQL

How to rename column from table

To rename a column from an existing table, run the following command:

alter table table_name change old_column_name new_column_name attribute;

example:

alter table EXAMPLE change ONE TWO varchar(25);

Comments Off on How to rename column from table Posted in MySQL

How to insert data from one table to another

To insert records from table to another, run the following command:

insert into table_name select fields1,field2…from table_name;

example:

mysql> insert into EXAMPLE select FIRST,LAST from TEST;

To insert records from table to another without duplicate, run the following command:

insert ignore into table_name select fields1,field2… from table_name;

example:

mysql> insert ignore into EXAMPLE select FIRST,LAST from TEST;

Comments Off on How to insert data from one table to another Posted in MySQL

How to copy table

To create a table from another without data, run the following command:

create table new_table_name like source_table_name;

example:

mysql> create table EXAMPLE like SOURCE;

Comments Off on How to copy table Posted in MySQL