Insert MySQL Table from *.csv file

Setup local infile

Sebelum dapat melakukan load data secara local ke dalam database, maka perlu memastikan bahwa load infile dalam kondisi aktif

Periksa status local infile

mysql> show global variables like 'local_infile';

Akan memberikan informasi seperti di bawah ini:

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

Untuk mengaktifkan gunakan perintah berikut:

mysql> set global local_infile=true;

Setelah itu silahkan connect ke database dengan parameter local infile

mysql --local_infile=1 -u root -ppassword DB_name

Dan lakukan load data local, seperti:

mysql> load data local infile 'path/file_name.extention' into table table_name;

INSERT

Misalkan kita memiliki table berikut ini:

mysql> desc temp_user_info_data;
+------------+------------+------+-----+---------+----------------+
| Field      | Type       | Null | Key | Default | Extra          |
+------------+------------+------+-----+---------+----------------+
| id         | bigint(10) | NO   | PRI | NULL    | auto_increment |
| userid     | bigint(10) | NO   | MUL | 0       |                |
| fieldid    | bigint(10) | NO   |     | 0       |                |
| data       | longtext   | NO   |     | NULL    |                |
| dataformat | tinyint(2) | NO   |     | 0       |                |
+------------+------------+------+-----+---------+----------------+

Catatan: untuk melihat info lebih detail tentang table dan bagaimana table tersebut di buat, Anda dapat menggunakan perintah:

mysql> desc namatable

atau

mysql> show create table namatable;

Kemudian file data kita diletakkan di /root dengan nama file data *.csv: contoh.csv seperti berikut:

5791,23,11
19766,23,11

Lalu lakukan load data:

mysql> load data local infile '/root/contoh.csv' into table temp_user_info_data fields terminated by ',' (userid,fieldid,data);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 0

Jika data Anda memiliki satu baris pertama yang berisi nama kolom, maka berikan ignore 1 lines seperti berikut:

mysql> load data local infile '/root/contoh.csv' into table temp_user_info_data fields terminated by ',' ignore 1 lines (userid,fieldid,data);

Fix Error #551 in phpMyAdmin 18.04

Error message containts :

Warning in ./libraries/plugin_interface.lib.php#551
count(): Parameter must be an array or an object that implements Countable

Solution:

You can also fix this by editing the library itself.

  1. Make a backup first
    sudo cp /usr/share/phpmyadmin/libraries/plugininterface.lib.php /usr/share/phpmyadmin/libraries/plugininterface.lib.php.bak
  2. Edit the library
    sudo nano /usr/share/phpmyadmin/libraries/plugin_interface.lib.php
  3. Search for “if (! is_null($options) && count($options) > 0) {”
    or if not found then search for “if ($options != null && count($options) > 0) {”

Then replace it with “if ($options != null) {”

To search in Nano editor press CTRL and W

  1. Save the file (CTRL and O)
  2. Refresh the phpMyAdmin page and try agin.

PostgreSQL remote connection

This arcticle was writen based PostgreSQL version 10.10 and running on Ubuntu 18.04

Configuring postgresql.conf

Find postgresql.conf

$ find / -name "postgresql.conf"
/usr/lib/tmpfiles.d/postgresql.conf
/etc/postgresql/10/main/postgresql.conf

Open file /etc/postgresql/10/main/postgresql.conf and replace line

listen_addresses = 'localhost'

with

listen_addresses = '*'

Configuring pg_hba.conf

Open file /etc/postgresql/10/main/pg_hba.conf and add following entry at the very end

host    all             all     0.0.0.0/0                    md5
host    all             all     ::/0                         md5

Do not get confused by “md5” option mentioned above. All it means is that a password needs to be provided. If you want client to allow collection without providing any password then change “md5” to “trust” and that will allow connection unconditionally.

Restart postgresql server.