[HOW TO] ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Hello,

I wanted to export the csv file from MySQL command line. And used the guide following the article [HOW TO] Export mysql result to csv file

All are good if there is no any issue.
mysql> select * from devices where status = '2' INTO OUTFILE '/tmp/PLC_active.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

It means that my MySQL server has been started with --secure-file-priv option which basically limits from which directories you can load files using LOAD DATA INFILE

so I have two options
1. Move the file to specified directory
2. Disable --secure-file-priv

Now, I choose option 1.

mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.00 sec)
mysql> select * from devices where status = '2' INTO OUTFILE '/var/lib/mysql-files/PLC_active.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 769 rows affected (0.00 sec)

mysql> select * from devices where status != '2' INTO OUTFILE '/var/lib/mysql-files/PLC_inactive.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 113 rows affected (0.01 sec)

These files can export without any issue.

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] install Visual Studio Code in Arch Linux

I am moving Linux working environment from Ubuntu to Antergos. And I need to install Visual Studio Code for working with Git. 

Also saw something on this progress that is needed for newbie. So I write down this article. Hope it can be help you faster. 

This article follows step-by-step theory, so it is easy to do. 

Step 1:
You must download git repository 
[root@cliff Downloads]# git clone https://AUR.archlinux.org/visual-studio-code-bin.git

Step 2:
Then go inside 
[root@cliff Downloads]# cd visual-studio-code-bin/
[root@cliff visual-studio-code-bin]# ls
PKGBUILD  visual-studio-code.desktop  visual-studio-code-url-handler.desktop

Step 3:
And make a pacman package
[cliff@cliff visual-studio-code-bin]$ makepkg -s
==> Making package: visual-studio-code-bin 1.33.1-1 (Mon 29 Apr 2019 03:59:40 PM +07)
==> Checking runtime dependencies...
==> Installing missing dependencies...
...
==> Finished making: visual-studio-code-bin 1.33.1-1 (Mon 29 Apr 2019 04:00:34 PM +07)

makepkg should download *.tar.gz from Visual Studio Code and convert it to pacman package 
==> Finished making: visual-studio-code-bin 1.33.1-1 (Mon 29 Apr 2019 04:00:34 PM +07)

Step 4:
Then install 
[cliff@cliff visual-studio-code-bin]$ sudo pacman -U visual-studio-code-bin-1.33.1-1-x86_64.pkg.tar 

Step 5:
Finally, you can start it for now. I am using i3, so can take it via Ctrl + D and type "visual studio code" and press. 

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] fix ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Hey guys,

I am working with MySQL, then want to export the data to csv file. 
mysql> select name,address from devices into outfile '/tmp/devices.csv' fields terminated by ',' enclosed by '"' lines terminated by '\n';ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Oops! unlucky, it returns the error. Before me, someone started MySQL with --secure-file-priv
mysql> SHOW VARIABLES LIKE "secure_file_priv"; 
+------------------+-----------------------+| 
Variable_name    | Value                  
|+------------------+-----------------------+| 
secure_file_priv | /var/lib/mysql-files/ | 
+------------------+-----------------------+ 
1 row in set (0.00 sec)

it looks like that all of files store at /var/lib/mysql-files/ as declared. Then I try to export again.
mysql> select name,address from devices INTO OUTFILE '/var/lib/mysql-files/orders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';Query OK, 891 rows affected (0.01 sec)

it works!!!


Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 


[HOW TO] set application log to rsyslog on Ubuntu server

Depending on your application, also your purpose, you want to direct the log to fixed log path. So, if you are using rsyslog as a syslog service on Ubuntu, please follow this article.

I am using trigger to do this.

Go to log path
root@sta-tn:/etc/rsyslog.d#

then write a sub-rsyslog configuration.
root@sta-tn:/etc/rsyslog.d# vim 10-sta.conf 
if $programname == 'STA'  then {  
/var/log/sta.log    
stop 
}

You can declare more directive here. Then restart rsyslog service
root@sta-tn:/etc/rsyslog.d# systemctl restart rsyslog

Another way, you can use imfile module to do this.

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] The following signatures couldn't be verified because the public key is not available: NO_PUBKEY

sky@zabbix4-srv-01:/opt/packages$ sudo apt-get updateGet:1 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial InRelease [7096 B]Hit:2 http://security.ubuntu.com/ubuntu xenial-security InReleaseGet:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]Hit:4 http://us.archive.ubuntu.com/ubuntu xenial InReleaseGet:5 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main Sources [1196 B]Ign:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InReleaseHit:6 http://us.archive.ubuntu.com/ubuntu xenial-updates InReleaseGet:7 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main amd64 Packages [2697 B]Get:8 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main i386 Packages [2685 B]Hit:9 http://us.archive.ubuntu.com/ubuntu xenial-backports InReleaseFetched 37.5 kB in 1s (33.2 kB/s)Reading package lists... DoneW: GPG error: http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6CW: The repository 'http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease' is not signed.N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.N: See apt-secure(8) manpage for repository creation and user configuration details.

sky@zabbix4-srv-01:/opt/packages$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6CExecuting: /tmp/tmp.8btYCLAEE0/gpg.1.sh --keyserverkeyserver.ubuntu.com--recv-keys4F4EA0AAE5267A6Cgpg: requesting key E5267A6C from hkp server keyserver.ubuntu.comgpg: key E5267A6C: public key "Launchpad PPA for Ond\xc5\x99ej Sur�" importedgpg: Total number processed: 1gpg:               imported: 1  (RSA: 1)


sky@zabbix4-srv-01:/opt/packages$skylab@zabbix4-srv-01:/opt/packages$ sudo apt-get updateHit:1 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial InReleaseHit:2 http://security.ubuntu.com/ubuntu xenial-security InReleaseGet:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]Hit:4 http://us.archive.ubuntu.com/ubuntu xenial InReleaseHit:5 http://us.archive.ubuntu.com/ubuntu xenial-updates InReleaseHit:6 http://us.archive.ubuntu.com/ubuntu xenial-backports InReleaseFetched 23.9 kB in 1s (22.1 kB/s)Reading package lists... Done

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success