2015年5月4日 星期一

MySQL語法

1. Login MySQL with password
$mysql -u -root -p
Enter password:

2. How to get a list of user accounts
mysql> SELECT User FROM mysql.user;

3. How to delete user
mysql> DROP USER 'user_name'@'localhost';

4. Create user
mysql>CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'user_name';

5. Change user password
mysql> UPDATE user SET Password=PASSWORD("your_password") WHERE User='user_name';

6List all database
mysql>SHOW DATABASES;

7. Show current use database
mysql>SELECT DATABASE();

8. Change database
mysql>use database_name;

9. Create database
mysql>CREATE DATABASE db_name;

10. Delete database
mysql>DROP DATABASE db_name;

11. allow user to connect to the server from localhost with password
mysql>grant usage on *.* user_name@localhost identified by'user_password';

12. grant all privileges on database to this user
mysql>grant all privileges on db_name.* to user_nae@localhost;

13. Show tables
mysql>SHOW TABLES FROM db_name;

14 Show all tables
mysql>SHOW TABLES;

15. Show data from table
mysql>select * from table_name;

16. update column
update 資料表名稱 set 欄位1='值1',欄位2='值2',欄位3='值3',... 欄位N='值N'
where 條件式 (例如 sn='5' 或 name='塔司尼' );


2015年2月10日 星期二

How to setup NFS in Ubuntu

How to setup NFS in Ubuntu

  1. install nfs
$sudo apt-get install nfs-kernel-server
  1. check hosts name
$hostname --fqdn
ex:
$hostname --fqdn
usernamehost
The host name could not have special character, like "-, _, ", only "usernamehost". if return error, modify the host name, log-out then log-in.
$sudo vim /etc/hosts
127.0.1.1 kelseylaiAS5551
.
  1. setup nfs
$vim /etc/hosts.allow
portmap: [tv_ip]
lockd: [tv_ip]
rquotad: [tv_ip]
mountd: [tv_ip]
statd: [tv_ip]
ex:
$sudo vim /etc/hosts.allow
...
portmap: 192.168.0.107
lockd: 192.168.0.107
rquotad: 192.168.0.107
mountd: 192.168.0.107
statd: 192.168.0.107
/etc/hosts.deny /etc/hosts.allow 設定對portmap的訪問. 採用這兩個配置檔案有點類似黑名單,白名單的意思. 先在/etc/hosts.deny中禁止所有用 戶對portmap的訪問.再在/etc/hosts.allow 中允許某些特殊用戶對portmap的訪問。
  1. modify NFS directory permission

$sudo vim /etc/exports
/home/NFS 192.168.0.*(rw,sync,no_root_squash)

$exportfs -r

NFS掛載目錄及權限由/etc/exports檔案定義
例如,我在家目錄下建立一個名為NFS的目錄,作為共享給板子的,則在該檔案裡加入
/home/NFS/192.168.0.*(rw,sync,no_root_squash)
  1. make direcotry for NFS
$mkdir [you_want_nfs_path]
ex:
$sudo mkdir /home/NFS

   6. restart nfs server
$sudo service nfs-kernel-server restart