MySQL

一、查看 MySQL 设置的变量值:SHOW VARIABLES; 详情见 SHOW 语法:http://dev.mysql.com/doc/refman/5.5/en/show.html

二、windows 下忘记 root 密码的解决方法:
1、关闭 MySQL 服务
2、cmd 进入 mysqld 所在文件夹
3、cmd 下运行 mysqld –skip-grant-tables # 跳过授权表启动 MySQL 服务
4、打开新的 cmd 窗口
运行 mysql -uroot -p
提示输入密码继续回车 # 此时 root 的密码为空
use mysql # 选择 mysql 库
UPDATE user SET Password=PASSWORD(‘newpassword’) where USER=’root’; # 更改 root 密码
FLUSH PRIVILEGES; # 刷新权限,至此,完成

三、查看 MySQL-Server 的详细信息(加载配置文件的路径)
cmd 模式进入这个目录 \Program Files\MySQL\MySQL Server5.6\bin
运行:mysqld –verbose –help
在输出里面查找 “Default options are read from the following files in the given order” 就可以找到配置文件的路径。
或者,在计算机管理-服务里面找到 MySQL 的服务,查看服务属性,你就会看到加载的配置文件了。

四、开启慢查询

set global long_query_time=2;
set global slow_query_log=1;

五、mysql按编码计算字符长度而不是字节数, varchar(100) 表示容量为100个utf-8编码的字符个数,不是100个字节,插入超过容量长度的字符会被自动截断。如果varchar设定了utf8编码,varchar(2) => 两个汉字,比如[你好]。

六、As of MySQL 5.1.29, the –log-slow-queries option is deprecated and is removed (along with the log_slow_queries system variable) in MySQL 5.6. Instead, use the –slow_query_log option to enable the slow query log and the –slow_query_log_file=file_name option to set the slow query log file name.

七、In MySQL, JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents (they can replace each other). In standard SQL, they are not equivalent. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise.

八、重命名表语句:ALTER TABLE `旧表名` RENAME TO `新表名`;

九、今天出现错误:Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_c,IMPLICIT) for operation ‘=’。两个表在 JOIN 查询时,因为表的编码不一样,导致出现此错误,请将编码改为 utf8_general_ci 即可(2013-11-08 18:29:03)

VIM 配置和使用

本文常更新,记录笔者在使用 VIM 的过程中,用到的一些 tips

配置:

1、根据文件类型自动设置不同的缩进值:
autocmd FileType html set ts=2 sts=2 sw=2
autocmd FileType javascript set ts=4 sts=4 sw=4

2、KDE 下 konsole 启动 vim 如果要正常使用配色需要环境变量 TERM=xterm-color256 (2013-09-07 15:22:07)

另外我的配置文件在这里:https://github.com/upliu/dotfiles

使用:

1、插入当前文件名:在 insert 模式下按:Ctrl-R % 或者 在 normal 模式下按:”%p

2、复制内容到系统剪切板:在 normal 模式下按:”+y
粘贴系统剪切板的内容到vim:在 normal 模式下按:”+p
相关知识:查看寄存器::reg
(Ubuntu 13.04 安装 vim 后没有 + 寄存器,得安装 vim-gui-common 后才有 + 寄存器)
(Ubuntu 默认终端下可以 Ctrl-Shift-C 复制 Ctrl-Shift-V 粘贴,更正错误,不能 C-S-C 复制,但是可以选中后 C-S-V 粘贴)

3、查找当前串:normal 模式下按 * (Shift+8) 键

4、zen-coding 默认绑定键:Ctrl+Y+,

5、查找贪婪模式 .* 非贪婪模式 .\{-}

6、删除匹配行 g/pattern/d(删除空行:g/^$/d)

7、删除不匹配行 g!/pattern/d 或 v/pattern/d

8、跳转到匹配的括号:%

9、删除换行符:命令模式下按 J(大写的 j)

10、显示回车换行等特殊字符:set list

11、删除空行 :g/^\s*$/d

12、忘记sudo :w !sudo tee %

Eclipse 快捷键

一直都不太喜欢用 Eclipse 因为实在是习惯了 vim 的快捷键操作方式,但是呢,vim 又用的不到家,当 IDE 使还不够,所以,现在修改单个文件的时候用 vim,但是开发项目时还是用 Eclipse。

这篇文章包含我需要用到的 Eclipse 快捷键:

删除当前行:Ctrl+D
在当前行上插入一行:Ctrl+Shift+Enter Shift+Enter
在当前行下插入一行: Shift+Enter
上下移动选中的行:Alt+Up/Down
打开资源:ctrl+shift+r
Emmet(原zen-coding)默认快捷键为:Ctrl+E