MySQL 管理用户与访问授权

MySQL 创建用户、修改密码、删除用户;查看、授予、撤销用户权限;对 MySQL 远程访问的新理解。 -- 创建用户 + 授权 GRANT ALL PRIVILEGES ON _._ TO 'tom'@'%' IDENTIFIED BY 'pwd123' WITH GRANT OPTION; -- 查询权限 SHOW GRANTS FOR 'tom'@'%'; -- 授权 GRANT SELECT ON `my_db`.* TO 'tom'@'%'; -- 撤权 REVOKE ALL PRIVILEGES ON `my_db`.* FROM 'tom'@'%'; REVOKE GRANT OPTION ON `my_db`.* from 'tom'@'%'; -- not necessary FLUSH PRIVILEGES; 管理用户 创建用户 CREATE USER 'username'@'host' IDENTIFIED BY 'password'; username:创建的用户名 host:该用户在哪个主机上可以登陆。如果是本地用户可用 localhost;如果想让该用户可以从任意远程主机登陆,可以使用通配符 % password:该用户的登陆密码。密码可以为空,如果为空则该用户可以不需要密码登陆服务器 例子: ...

April 11, 2017 · 2 min · 376 words · Me

Ubuntu 命令行下免密码执行 sudo 命令

解决你的问题的方法是将你的用户加入 sudoers 文件。 sudo visudo 在文件底部输入: username ALL=(ALL) NOPASSWD: ALL 这只适用于终端窗口中的 sudo 命令。例如,当你尝试在 software center 中安装软件包时,将提示你输入密码。 References command line - Execute sudo without Password? - Ask Ubuntu

April 10, 2017 · 1 min · 27 words · Me

Ubuntu 下使用 sendmail mail 发送邮件

使用邮件发送程序的执行情况、运行日志都非常方便,Ubuntu 下搭建邮件服务也不复杂。 sendmail install sudo apt-get install sendmail configure run sendmail’s config and answer Y to everything sudo sendmailconfig mail install sudo apt-get install mailutils test echo 'test-email-content' | mail -s 'email title' xxx@gmail.com sendmail mail 区别 先需要搞清三个概念: 邮件用户代理(MUA,Mail User Agent) 邮件传送代理(MTA,Mail Transport Agent) 邮件分发代理(MDA,Mail Deliver Agent) sedmail 是负责邮件传输的 MTA,类似 apache、nginx 的作用。mail 是用户使用客户端 MUA,类似 foxmail。 References Install and configure Sendmail on Ubuntu Linux 下 mail、mailx 和 sendmail 的区别? - 知乎

April 6, 2017 · 1 min · 70 words · Me

Git 在工作目录之间使用 push 进行同步

Pushing to a non-bare repo is now possible (Git 2.3.0 February 2015). And it is possible when you are pushing the branch currently checked out at the remote repo! 现在已经是可以在俩个 non-bare 的仓库之间推送代码。 只需要再远程仓库配置: git config receive.denyCurrentBranch updateInstead 就可以直接 push 分支到远程,并更新工作区。此方法可以用于项目部署。 receive-pack: add another option for receive.denyCurrentBranch When synchronizing between working directories, it can be handy to update the current branch via ‘push’ rather than ‘pull’, e.g. when pushing a fix from inside a VM, or when pushing a fix made on a user’s machine (where the developer is not at liberty to install an ssh daemon let alone know the user’s password). ...

March 30, 2017 · 1 min · 184 words · Me

解决 SSH 连接提示 Permission denied publickey

服务器是使用 publickey 进行连接,当在 git push 时发生 Permission denied (publickey)。同时解决 ssh-add 重启后失效。 解决 ssh-add your_publickey 如果遇到报错 Could not open a connection to your authentication agent. Try to eval `ssh-agent` 注意: 在重启电脑后失效,一直没有找的其他合适的解决方案,所以选择在 ~/.bashrc 或 ~/.zshrc 中添加: ssh-add your_publickey 2> /dev/null 2> /dev/null 是为了保持静默运行 References ssh 连接提示 Permission denied (publickey) 怎么破? | 吴川斌的博客

March 30, 2017 · 1 min · 50 words · Me

解决 Ubuntu Sogou 无法选词输入中文

sogou 输入法突然无法选词输入中文,候选词位置出现白框,多次重重装 fcitx 和 sogou 也没有解决。尝试使用 google pinyin 代替,但是感觉很不顺手。 issue in GitHub sogou 输入法 GitHub 上的一些 issue: #43 #177 #179 解决 方案一 try to lastest version 方案二 clean fcitx, SogouPY*, sogou-qimpanel in ~/.config, then relogin and try again cd ~/.config sudo rm -rf fcitx SogouPY sogou-qimpanel References ubuntu-sogou-不能显示候选词 | Color Win’s Notes – EOF –

March 17, 2017 · 1 min · 55 words · Me

Git pull rebase 和 merge no-ff 保持提交线图整洁

git log 中的一个清晰的提交线图是很方便进行 code review 和代码回退 git pull --rebase 主要是为是将提交约线图平坦化,而 git merge --no-ff 则是刻意制造分叉 pull rebase perform a rebase after fetching 状况 Git 作为分布式版本控制系统,所有修改操作都是基于本地的,在团队协作过程中,假设你和你的同伴在本地中分别有各自的新提交,而你的同伴先于你 push 了代码到远程分支上,所以你必须先执行 git pull 来获取同伴的提交,然后才能 push 自己的提交到远程分支。 按照 Git 的默认策略,如果远程分支和本地分支之间的提交线图有分叉的话(即不是 fast-forwarded),Git 会执行一次 merge 操作,因此产生一次没意义的提交记录,从而造成了像上图那样的混乱。 解决 其实在 pull 操作的时候,使用 git pull --rebase 选项即可很好地解决上述问题。 加上 --rebase 参数的作用是,提交线图有分叉的话,Git 会 rebase 策略来代替默认的 merge 策略。 假设提交线图在执行 pull 前是这样的: A---B---C remotes/origin/master / D---E---F---G master 如果是执行 git pull 后,结果多出了 H 这个没必要的提交记录。提交线图会变成这样: ...

March 17, 2017 · 2 min · 231 words · Me

禁止 Google 根据区域重定向跳转

使用代理上 Google 时,Google 常会根据网络代理的区域进行重定向跳转。例如:使用韩国代理时,google.com 会跳转到 https://www.google.co.kr/,搜索结果也多为韩语,很是不方便。 解决的办法其实也很简单:访问 https://www.google.com/ncr 就可以了。 ncr 表示:No Country Redirection,禁止区域重定向。 – EOF –

March 14, 2017 · 1 min · 16 words · Me

Git 修改提交历史

在使用 Git 时,我们经常会遇到修改本地提交记录的情况。比如:修改最近一次提交记,还比如:将多次小的 commit 合并成一个大的 commit。 这种做发有利也有弊,利在:review 代码时,可以按功能看,可以省去 review 一些前期写的无效的代码;弊是:一次提交修改过多,如果有问题,不利于调试。 具体情况具体分析,是解决问题的金句。 修改最近一次提交记录 修改提交说明 如果只想更改最近一次的提交说明,只需输入: git commit --amend 然后你就会进入文本编辑器,输入你想要的内容,保存并退出即可 改被提交的快照 如果你完成 commit 后又想修改被提交的快照,增加或者修改其中的文件。 先执行 git add 命令,将修改的文件添加到缓存区,然后运行 git commit -amend 命令,该命令会获取你当前的暂存区的内容一并提交到最后一次 commit 例如:新加了一个文件 new_file.cpp ,想要合并到最后一次提交,过程如下: git add new_file.cpp git commit -amend 也可以直接运行下面的命令,不过要小心,不要提交了多余的文件 git commit -a -amend 将文件从本次提交中移除 如果想把已经 commit 的文件从这次 commit 移除的话,运行命令: git reset [-soft] HEAD~1 # -soft可加可不加,默认就是soft选项 git checkout -filename # 要从本次提交移除的文件名 git commit -m "new commit" 修改多个提交记录 要修改历史中更早的提交,你必须采用更复杂的工具。Git 没有一个修改历史的工具,但是你可以使用 rebase 工具来衍合一系列的提交到它们原来所在的 HEAD 上。 ...

March 13, 2017 · 3 min · 531 words · Me

PHP empty 方法判断 0.0

在使用 empty(mixed $var) 时要考虑 $var 的 类型,尤其是在判断数据库查询后的字段。 bool empty(mixed $var) 以下的东西被认为是空 true 的: ""(空字符串) 0 (作为整数的 0) 0.0 (作为浮点数的 0) "0" (作为字符串的 0) NULL FALSE array() 一个空数组 $var 未初始化的变量 new stdClass() 不包含任何属性的对象 注意: string 的判断要非常注意,数据库查询后的字段常常为 string,应该进行正确的类型转换。 以下的东西被认为是非空 false 的: $var = true; $var = 1; $var = -1; $var = “0.0”; $var = “foo”; $var = array(0); $var = new stdClass(); $var->property = null; $str = '0.0'; echo empty($str); // false 很可能和预期是相反的 echo empty((float)$str); // true – EOF – ...

March 9, 2017 · 1 min · 79 words · Me