Import file local (txt,csv) ke mysql

2 hari lalu (tanggal 5 mei 2014) saya mau import file csv ke mysql melalui phpmyadmin. (maklum newbie, jadi taunya hanya melalui itu 😀 )

tapi filenya terlalu besar sekitar 82 MB walaupun sudah saya setting di php.ini menjadi 128 MB tetap gagal waktu import 😦

jadi saya googling akhirnya dapat caranya….

1. login ke mysql.

mysql -u root -p –local-infile

2. gunakan database yang ingin kita import

use nama_database

3. perintah import

LOAD DATA LOCAL INFILE ‘path nama_file.txt’ INTO TABLE nama_tabel fields terminated by ‘,’ enclosed by ‘”‘;

cuma itu, kalo Anda masih ada yg gagal silahkan kontak ke twitter @emmank

Terimakasih

Iklan

Cursors Mysql

MySQL supports cursors inside stored programs. The syntax is as in embedded SQL. Cursors have these properties:

  • Asensitive: The server may or may not make a copy of its result table
  • Read only: Not updatable
  • Nonscrollable: Can be traversed only in one direction and cannot skip rows

Cursor declarations must appear before handler declarations and after variable and condition declarations.

Example:

CREATE PROCEDURE curdemo()
BEGIN
  DECLARE done INT DEFAULT FALSE;
  DECLARE a CHAR(16);
  DECLARE b, c INT;
  DECLARE cur1 CURSOR FOR SELECT id,data FROM test.t1;
  DECLARE cur2 CURSOR FOR SELECT i FROM test.t2;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

  OPEN cur1;
  OPEN cur2;

  read_loop: LOOP
    FETCH cur1 INTO a, b;
    FETCH cur2 INTO c;
    IF done THEN
      LEAVE read_loop;
    END IF;
    IF b < c THEN
      INSERT INTO test.t3 VALUES (a,b);
    ELSE
      INSERT INTO test.t3 VALUES (a,c);
    END IF;
  END LOOP;

  CLOSE cur1;
  CLOSE cur2;
END;
http://dev.mysql.com/doc/refman/5.0/en/cursors.html