2018年4月10日

MariaDB建立資料庫、帳號、權限的SQL語法

建立資料庫:

MariaDB [(none)]> CREATE DATABASE `dbname` CHARACTER SET utf8 COLLATE utf8_general_ci;

建立使用者:

MariaDB [(none)]> CREATE USER 'user' IDENTIFIED BY 'password';

 建立連接許可權:

MariaDB [(none)]> GRANT USAGE ON *.* TO 'user'@localhost IDENTIFIED BY 'password';

授予資料庫權限:

MariaDB [(none)]> GRANT ALL privileges ON `dbname`.* TO 'user'@localhost;

更新權限:

MariaDB [(none)]> FLUSH PRIVILEGES;

2018年3月20日

apt 指令強制使用 ipv4 連線

最近學校的 Ubuntu Server 國家高速網路中心的mirror 站進行更新時有時會連不到或是很緩慢的問題,發現是 ipv6 連線的問題,只要改成強制使用 ipv4 連線就好了;以下是更新的指令:
sudo apt -o Acquire::ForceIPv4=true update && sudo apt -y -o Acquire::ForceIPv4=true full-upgrade

2018年3月16日

在Ubuntu上安裝Composer

在UBUNTU上並沒有Composer這個指令,所以要另外安裝,安裝流程如下:

  1. 更新APT資料庫
  2. sudo apt update
  3. 安裝必要套件
  4. sudo apt install curl php7-cli php7-mbstring git unzip
  5. 下載Composer安裝程式
  6. curl -sS https://getcomposer.org/installer -o composer-setup.php
  7. 取得Composer的Signatures
  8. 網址: https://composer.github.io/pubkeys.html 找到"Installer Signature (SHA-384)",把下面那一串字串記起來。
  9. 驗證Composer的安裝程式
  10. php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" 
    若是出現Installer verified,則代表驗證無誤。
  11. 執行Composer安裝設定程式
  12. sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    有出現 "Composer (version 1.6.3) successfully installed to: /usr/local/bin/composer" 就代表已經安裝成功了

2018年2月12日

從PKCS12 (副檔名為 pfx) 格式的憑證轉出public key及private key

取出憑證的Public Key:
openssl pkcs12 -in server.pfx -clcerts -nokeys -out server.crt
取出憑證的Private Key:
openssl pkcs12 -in server.pfx -nocerts -nodes -out server.key

2018年2月5日

print char to hex in c language

在C語言裡想要印出char的內碼有時會發生印出4個byte的資料,例如ffffffc0 ffffffc0,要解決這問題的方式很簡單,只要在print out之前先對0xff做AND計算後再輸出就可以解決了。Ex:
printf("%x", ch & 0xff);

ubuntu 執行 apt full-upgrade 後出現錯誤訊息的處理方法

執行apt full-upgrade後出現以下的訊息,雖然不影響系統,但是每次有image install時都會出現,覺得有點礙眼,所以就找了一下解決的辦法。
WARNING: missing /lib/modules/4.4.0-87-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.4.0-87-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_BSmOjQ/lib/modules/4.4.0-87-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_BSmOjQ/lib/modules/4.4.0-87-generic/modules.builtin: No such file or directory
解決的方法有以下兩種:
  1. 直接去刪除 /var/lib/initramfs-tools 目錄下出問題的initramfs腳本,本例是4.4.0-87-generic,所以就直接刪除4.4.0-87-generic這個檔案。
  2. 執行update-initramfs指令,例如: update-initramfs -d -k 4.4.0-87-generic

精選文章

Ubuntu 20.04 LTS VM syslog 出現 multipathd 錯誤時的處置措施

在 VM 上安裝完 Ubuntu 20.04 LTS 版本後在一次例行性檢查中發現 syslog 中發現一直跳出 multipathd 的錯誤,如下圖 這問題產生的原因是 ESXi 不會產生 udev 必要的資訊,所以 udev 就無法產生出相對應的 /dev/disk/by-i...