MySQL索引使用策略及优化

创建索引

  • 在经常查询而不经常增删改操作的字段加索引。
  • order by与group by后应直接使用字段,而且字段应该是索引字段。
  • 一个表上的索引不应该超过6个。
  • 索引字段的长度固定,且长度较短。
  • 索引字段重复不能过多。
  • 在过滤性高的字段上加索引。

使用索引注意事项

  • 使用like关键字时,前置%会导致索引失效。
  • 使用null值会被自动从索引中排除,索引一般不会建立在有空值的列上。
  • 使用or关键字时,or左右字段如果存在一个没有索引,有索引字段也会失效。
  • 使用!=操作符时,将放弃使用索引。因为范围不确定,使用索引效率不高,会被引擎自动改为全表扫描。
  • 不要在索引字段进行运算。
  • 在使用复合索引时,最左前缀原则,查询时必须使用索引的第一个字段,否则索引失效;并且应尽量让字段顺序与索引顺序一致。
  • 避免隐式转换,定义的数据类型与传入的数据类型保持一致。

Ubuntu下Vmvare卡顿的问题

Ubuntu: VMware and mount.ntfs high cpu usage fix

If we run VMWare player on Ubuntu to run guest OS, and if the virtual machine files are stored in a NTFS partition (like a large External HDD), then chances are that you would notice mount.ntfs taking up almost 100% cpu usage once the Vmware’s Image is started. This will most certainly leave your system unusable until you are able to get the vmware down.

The old remedy of changing the .vmx file and adding mainMem.useNamedFile = "FALSE" does not work any more. As per this post, the solution is to provide a non-ntfs location for storing the vmware suspend and snapshot files as a working directory. The same can be edited in the vmplayer’s option screen as shown below or added as a line in the .vmx file as workingDir = “../../../opt/vmware”

Ensure the directory provided has write permissions for the user configured to run the vm.

Kubectl命令提示自动补全

更多可以参考Kubernetes中kubectl的文档:https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion

启用 shell 自动补全功能

kubectl已经包含了自动补全的支持,kubectl可以自动生产补全脚本,因此只需要将其加入profile即可

常见启用方式如下,更多功能可以使用 kubectl completion -h 查看.

On Linux, using bash

在CentOS上, 如果没有安装过需要先按照bash-completion.

yum install bash-completion -y

然后执行以下命令即可临时启用自动补全功能,但是退出当前shell后会失效 

source <(kubectl completion bash).

运行下面的命令添加自动补全脚本到配置文件中,在启动时自动加载

echo "source <(kubectl completion bash)" >> ~/.bashrc

On macOS, using bash

On macOS, you will need to install bash-completion support via Homebrew first:

## If running Bash 3.2 included with macOS
brew install bash-completion
## or, if running Bash 4.1+
brew install bash-completion@2

Follow the “caveats” section of brew’s output to add the appropriate bash completion path to your local .bashrc.

If you installed kubectl using the Homebrew instructions then kubectl completion should start working immediately.

If you have installed kubectl manually, you need to add kubectl autocompletion to the bash-completion:

kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl

The Homebrew project is independent from Kubernetes, so the bash-completion packages are not guaranteed to work.

Using Zsh

If you are using zsh edit the ~/.zshrc file and add the following code to enable kubectl autocompletion:

if [ $commands[kubectl] ]; then   
source <(kubectl completion zsh)
fi

Or when using Oh-My-Zsh, edit the ~/.zshrc file and update the plugins= line to include the kubectl plugin.

plugins=(kubectl)