/** * @param port network port for listening * @param wd working directory, files will be saved into this folder */ publicFileTransferServer(int port, String wd) { this.port = port; this.wd = wd; }
# 定义数组 ARR=(a b c) # ARR[@]: 数组转换为字符串 echo "${ARR[@]}" a b c # ARR[*] echo "${ARR[*]}" a b c # 数组赋值 ANOTHER=("${ARR[@]}") # 长度 echo ${#ARR[@]} 3 # 序号 for idx in "${!ARR[@]}"; do echo "$idx" done
[@] VS [*]
数组的 [@] 和 [*] 都是取所有元素,但是有所差别。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# 定义 $ ARR=(a b c) $ A=("${ARR[@]}") $ B=("${ARR[*]}") # A $ echo${#A[@]} 3 $ echo${A[@]} a b c # B $ echo${#B[@]} 1 $ echo${B[@]} a b c
布尔
1 2 3 4
FLAG=true if [[ $FLAG == true ]]; then # do something fi
while command do Statement(s) to be executed if command is true done
示例
1 2 3 4 5 6 7 8 9
a=0 while [ $a -lt 10 ] do echo $a a=`expr $a + 1` done # 等待 port while ! lsof -i:8080; do echo "wait for server ready"; sleep 1; done
数组
1 2 3 4 5 6 7 8 9 10
# 命令行 $ countries=(china us); for country in${countries[@]}; echo$country china us # 脚本 countries=(china us) for country in ${countries[@]}; do echo $country done
范围
1 2 3 4 5 6 7 8 9 10 11 12 13
$ foridin {1..3}; echo$id# 1 2 3 # 脚本 for id in {1..3}; do echo $id done # seq [首数] [增量] 尾数 $ seq 1 3 # [1, 3] $ seq 3 # [1, 3] $ seq 1 2 5 # 1, 3, 5 $ for i in `seq 3`; doecho$i; done# 1 2 3
case…esac
1 2 3 4 5 6 7 8 9 10 11 12
word=a case $word in a) echo "a $word" ;; b) echo "b $word" ;; *) echo "* $word" ;; esac
getopts
参数
1 2 3 4 5 6
# opts :前缀 忽略错误 :后缀 参数后必须有值 # example :abc:de: 忽略参数错误,-c、-e后必须有值
while getopts ":ab:Bc:" opt; do case $opt in a) echo "found -a" ; a="hello" ;; b) echo "found -b and value is: $OPTARG" ;; c) echo "found -c and value is: $OPTARG" ;; *) usage ;; esac done
# install $ xcode-select --install # delete $ sudo rm -rf `xcode-select -p` # 一般会在文件夹 /Library/Developer/CommandLineTools 内 # Problems ## Can’t install the software because it is not currently available from the Software Update server. # 手动下载 https://developer.apple.com/download/more/?=command%20line%20tools
mysql -h localhost --port 3306 -u root -p --socket=/var/lib/mysql/mysql.sock #### 示例 bovenson@MBP:~/Git/notes/MySQL$ mysql -h localhost -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
# set password for 用户名@localhost = password('新密码'); set password for root@localhost = password('123'); # 修改 ALTER USER 'user'@'localhost' IDENTIFIED BY 'pass';
系统用户
添加
1 2
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass'; CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
赋予权限
1 2 3
GRANT ALL ON *.* TO 'myuser'@'localhost'; GRANT ALL ON *.* TO 'myuser'@'%'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
刷新权限
1
> FLUSH PRIVILEGES;
允许远程连接
设置bind-address
1 2 3 4 5 6 7
# mysql sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf # mariadb /etc/mysql/mariadb.conf.d/50-server.cnf # 修改bind-address bind-address = 0.0.0.0
添加/修改账户
添加/修改账户允许的Host为%
命令行远程登录mysql服务器
1
mysql -u root -p -h 10.154.0.43 -P 3306
设置
1 2
> USE mysql; > UPDATE user SET Host='%' WHERE User='root' AND Host='localhost';