Senin, 30 Desember 2019

Create Events from Command Line MySQL

mysql> DROP EVENT `SchGetMobileNeraca` ;
             CREATE DEFINER = `root`@`%` EVENT `SchGetMobileNeraca`
            ON SCHEDULE EVERY 1 DAY STARTS '2014-01-01 04:00:00'
            ON COMPLETION NOT PRESERVE ENABLE
            DO CALL GetMobileNeraca();

Selasa, 10 Desember 2019

Create file service pada Linux Ubuntu

untuk membuat file yang bisa di jalankan menggunakan service pada linux pertama harus membuat file yang di letakan pada directory /sbin/

- sebagai contoh akan melakukan restart service mysql maka terlebih dulu membuat file :
example : rmysql
create file rmysql akan diletakan pada direktori /sbin/ dengan perintah pico

# pico /sbin/rmysql

1. tambahkan perintah didalam file rmysql tersebut sebagai berikut :

#!/bin/sh
sudo /etc/init.d/mysql restart

2. lalu simpan, dan sekarang file /sbin/rmysql sudah berisi command atau perintah untuk melakukan restart mysql
3. agar bisa di jalankan oleh user pada Linux, maka harus di tambahan permissien dengan cara :

#chmod 777 /sbin/rmysql

4. selanjutnya adalah membuat file yang berisi perintah untuk melakukan perintah /sbin/rmysql tersebut
5. file execute tersebut harus di letakan pada direktori /etc/init/ example : mysql_restart
6. create file tersebut dengan command sebagai berikut :

#pico /etc/init/restart_mysql.conf

7. lalu tambahkan perintah didalamnya sebagai berikut :

## restart mysql.conf
start on filesystem
exec /sbin/rmysql

8. lalu simpan, dan sekarang file /etc/init/restart_mysql.conf sudah berisi command perintah untuk melakukan eksekusi file /sbin/rmysql

9. untuk menjalankan file restart_mysql jalankan perintah sebagai berikut :

#service restart_mysql start|restart|stop
  • start : untuk menjalankan serrvice mysql
  • restart : untuk mematikan dan menjalankan ulang service mysql
  • stop : untuk mematikan service mysql


Good luck !


Kamis, 11 Juli 2019

Linux Redirect Error Output To File

I am a new Ubuntu Linux and bash shell user. I also know how to redirect output from display/screen to a file using the following

syntax:

cmd > file
ls > file

However, some time errors are displayed on screen. How do I store and redirect output from the computer screen to a file on a Linux or Unix-like systems?

[donotprint][/donotprint] Bash / ksh and other modern shell on Linux has three file descriptors:
  1. stdin (0)
  2. stdout (1)
  3. stderr (2)

Syntax To redirect all output to file

The syntax is as follows to redirect output (stdout) as follows:
command-name >  output.txt
command-name >  stdout.txt

Syntax To redirect all error to file

The syntax is as follows to redirect errors (stderr) as follows:
command-name 2> errors.txt
command-name 2> stderr.txt

Syntax to redirect both output (stdout) and errors (stderr) to different files

The syntax:
command1 > out.txt 2> err.txt
command2 -f -z -y > out.txt 2> err.txt

Syntax to redirect both output (stdout) and errors (stderr) to same file

The syntax is:
command1 > everything.txt 2>&1
command1 -arg > everything.txt 2>&1

Syntax to redirect errors (stderr) to null or zero devices

Data written to a null or zero special file is discarded by your system. This is useful to silence out errors (also know as ‘error spam’):
command1 2> /dev/null
command1 2> /dev/zero
command2 -arg 2> /dev/null
command2 -arg 2> /dev/zero

Tip: Use tee command to redirect to both a file and the screen same time

The syntax is:
command1 |& tee log.txt
## or ##
command1 -arg |& tee log.txt
## or ##
command1 2>&1 | tee log.txt
Another usage:
#!/bin/bash
# My script to do blah ...
foo(){
 :
} 2>&1 | tee foo.log
OR
#!/bin/bash
# My script to do blah ...
{
   command1
   command2
} 2>&1 | tee script.log



https://www.cyberciti.biz/faq/linux-redirect-error-output-to-file/


Kamis, 20 Juni 2019

Howto resolve mysql error code1548 cannot load from mysql proc the table isprobably corrupted

MySQL will sometimes return the error message “Cannot load from mysql.proc. The table is probably corrupted”. This happens due to schema changes required for different MySQL server versions. The simple fix to this problem is to run the mysql_upgrade command from the command line.

About mysql_upgrade

mysql_upgrade examines all tables across all databases for incompatibilities with the current version of MySQL Server. mysql_upgrade also upgrades the system tables so that you can take advantage of new privileges or capabilities that might have been added.
mysql_upgrade should be executed each time you upgrade MySQL. It supersedes the older mysql_fix_privilege_tables script, which should no longer be used.
mysql_upgrade executes the following commands to check and repair tables and to upgrade the system tables:

mysqlcheck --all-databases --check-upgrade --auto-repair
mysql < fix_priv_tables

Run mysql_upgrade From Command Line

To use mysql_upgrade, make sure your MySQL server is running and then invoke mysql_upgrade from the command line tool:

mysql_upgrade -uroot -p --force


You should then be prompted to enter the MySQL root's password and mysql_upgrade will check all the databases and tables and fix them where appropriate. You may need to specify the full path to the above command if it's not in the shell's search path.

On Debian 6 it should be loacted at:

/usr/bin/mysql_upgrade -uroot -p --force

On Mac's MAMP the default path is:

/Applications/MAMP/Library/bin/mysql_upgrade -uroot -p --force


On Windows it'll be where MySQL is installed and contained in the bin subdirectory. By default it should be located at:


"C:\Program Files\MySQL\MySQL Server\[*CHANGE TO MySQL SERVER*]\bin\mysqladmin" -u root shutdown

VICTORY!

After running mysql_upgrade, stop the server and restart it so that any changes made to the system tables are ensured to take effect.
All checked and repaired tables are marked with the current MySQL version number. This ensures that next time you run mysql_upgrade with the same version of the server, it can tell whether there is any need to check or repair the table again.

http://www.myguysolutions.com/2013/10/30/how-to-resolve-mysql-error-code-1548-cannot-load-from-mysql-proc-the-table-is-probably-corrupted/

Selasa, 15 Januari 2019

Auto Mount Hardisk di Linux

Cara gampang untuk mount partisi di Linux adalah dengan memanfaatkan fstab, bila sudah ditambahakan di fstab setiap booting/reboot hardisk akan otomatis di mount
Jalankan blkid
/dev/sda1: LABEL="DATA" UUID="0cf51519-1b17-4861-8ca7-bbe119d6eac0" TYPE="ext4" PARTUUID="424fc3ac-b216-4f38-b144-6cd4f96c711e"
/dev/sdb1: SEC_TYPE="msdos" UUID="3E16-5919" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="62fbb27f-8970-46d6-99d3-a1d1d04a12311"
/dev/sdb2: UUID="3ee658e4-4f2c-42g9-9a9d-2f778ed5c87b" TYPE="ext4" PARTUUID="36c3fe5a-85c8-4f04-aaa8-a2ua60b4eywf0"
/dev/sdb3: UUID="gh21-h-kJLK-dd-dVzC-g0HQ-rws" TYPE="LVM2_member" PARTUUID="605tda7a-b1a1-4w2a-889f-d1da62bf3891"
Yang akan di mount otomatis adalah /dev/sda1
buka file /etc/fstab tambahkan

Partisi EXT4

UUID="0cf51519-1b17-4861-8ca7-bbe119d6eac0" /media/Film ext4 defaults 0 0

Partisi NTFS

UUID="0cf51519-1b17-4861-8ca7-bbe119d6eac0" /media/Film ntfs-3g  defaults,locale=en_US.UTF-8 0 0
buat folder /media/Film sebagai tempat mount partisi tersebut.
mkdir /media/Film
dengan menambahkan baris diatas di fstab maka hardisk yang di mount sewaktu booting bisa dibaca/tulis (read/write) oleh user.

Cara Partisi dan Format Hardisk di Linux dengan CLI

Cara untuk mempartisi dan format hardisk di Linux dengan CLI, utility yang akan kita gunakan adalah fdisk dan mkfs. Pilihan menggunakan command line, bila anda ingin memformat hardisk baru yang ditambahkan di server Linux yang tidak memiliki GUI, agar tidak salah partisi pastikan anda mengetahui Serial Number dan tipe hardisk, bisa di cek dengan perintah lsblk --nodeps -o name,serial,model
$ lsblk --nodeps -o name,serial,model
NAME SERIAL          MODEL
sda  WD-WCAW31471577 WDC WD1003FBXX-1
sdb  WD-WCAW31412727 WDC WD1003FBXX-1
Bila lsblk belum ter-install, install dengan
yum install lsblk
apt-get install lsblk

Cek Hardisk

Cek hardisk yang terdeteksi oleh Linux dengan perintah fdisk -l | grep -E '^Disk|/dev/*'
$  fdisk -l | grep -E '^Disk|/dev/*'
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Disk label type: dos
Disk identifier: 0x000cb8ad
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648  1951410175   975499264   83  Linux
/dev/sda3      1951410176  1953507327     1048576   82  Linux swap / Solaris
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Disk label type: dos
Disk identifier: 0x000bb114

Partisi Hardisk

fdisk /dev/sdb
output perintah diatas
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1953525167, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1953525167, default 1953525167): 
Using default value 1953525167
Partition 1 of type Linux and of size 931.5 GiB is set
 
Command (m for help): q
Pada tahap diatas kita memformat hardisk /dev/sdb menjadi 1 partisi dengan ukuran penuh 1 TB (931.5 GiB). Bila ingin membuat lebih dari 1 partisi dibagian Partition number masukkan 2, maksimalnya 4 partisi.

Format Hardisk

Karena saya hanya menggunakan 1 partisi, maka saya akan memformat seluruh hardisk /dev/sdb
mkfs.ext4  /dev/sdb
 
## output
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
....
....
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Mount Hardisk

Agar hardisk yang baru dipartisi bisa digunakan, mount hardisk tersebut ke folder /mnt, folder tempat mount bebas tidak harus di /mnt, bila folder belum ada, buat terlebih dahulu folder-nya sebelum di mount.
mount /dev/sdb /mnt