手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2024年09月的文章

linux下vim中文乱码的解决方法

新初装服务器的时候,有时候打开vim后中文是乱码,怎么处理呢?

最简单的办法:
XML/HTML代码
  1. 编辑~/.vimrc文件,加上如下几行:  
  2.   
  3.    set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936  
  4.    set termencoding=utf-8  
  5.    set encoding=utf-8  
OK,重新打开,搞定
 

Tags: vim

ThinkPHP group count

 如果用sql语句来写group by 再count,这样的sql太容易 了。但由于现在都是在用框架,反而这类sql变得难写了。最近在折腾一个用TP 3框架写的代码,原来代码里写的是:

PHP代码
  1. $count = D('Album')->table(T('albums AS a'))  
  2.                     ->join(T('union AS u') . ' ON u.id=a.union_id')  
  3.                     ->join(T('company AS c') . ' ON c.id=a.store_id')  
  4.                     ->join(T('photo AS p') . ' ON a.id=p.parent_id')  
  5.                     ->field('a.*,u.name AS union_name,c.name as store_name')  
  6.                     //     ->field('count(a.id)')  
  7.                     ->where($where)  
  8.                     ->group('a.id')  
  9.                     ->count();  

看起来好象没有问题,但事实上。出来的结果却并不是你想要的,这个count并不是你要的count,而是每个组的条数。当然你也可以用select()来查出数据,再count($count)一下,但如果数据量过大。这样会崩溃 的。

最终用这样的方法解决了:

PHP代码
  1. $numsQuery = D('Album')->table(T('albums AS a'))  
  2.                     ->join(T('union AS u') . ' ON u.id=a.union_id')  
  3.                     ->join(T('company AS c') . ' ON c.id=a.store_id')  
  4.                     ->join(T('photo AS p') . ' ON a.id=p.parent_id')  
  5.                     ->field('a.*,u.name AS union_name,c.name as store_name')  
  6.                     //     ->field('count(a.id)')  
  7.                     ->where($where)  
  8.                     ->group('a.id')  
  9.                     ->buildSql();  
  10. $nums = D()->table("{$numsQuery} as t")->count();  

算是曲线求国吧。

其实很多人在问这种问题了,但更多的人建议是直接写sql。我这种是不写sql的啦 ~

 

 

Error connecting remote MySQL server [ERROR 1042 (HY000): Can't get hostname for your address]

设置了远程数据库允许IP连接,也设置了bind ip为0.0.0.0 ,但有时候能连,有时候不能连接,而且还设置了是IP连接,报标题所在的错误,即 [ERROR 1042 (HY000): Can't get hostname for your address]。

开始就在想,是不是skip-name-resolve的问题,但因为我不是用host连接的,也不是内部的域名解析的问题。所以开始没注意,但google了之后,还是决定加了skipnameresolve

http://serverfault.com/questions/174242/error-connecting-remote-mysql-server-error-1042-hy000-cant-get-hostname-for
  1. ave MySQL 5.5 Server setup on a windows machine. I am able to connect to the server from console / app running on the same machine but not from a remote machine. While connecting using the command  
  2.   
  3. mysql -h xx.xx.xx.xx --port=3306 -u root -p  
  4. I get error as:  
  5.   
  6. ERROR 1042 (HY000): Can't get hostname for your address  
  7. Have tried putting entry of client ip in server's etc\hosts file as  
  8.   
  9. <client-ip>  <client-hostname>  
所有的回答都指向了skip-name-resolve
XML/HTML代码
  1. I believe this is to do with the fact that MySQL tries to establish the DNS name associated with your IP address on connect. See here for more information at the MySQL site.  
  2.   
  3. You have two options:  
  4.   
  5. 1) Fix the connecting machine's reverse DNS. Since you've already added the machine to the hosts file, this might be unnecessary. You should also issue a FLUSH HOSTS statement on the MySQL server. See the same link above for more information about this.  
  6.   
  7. 2) Run MySQL with the '--skip-name-resolve' option. However, if you do this, you won't be able to use DNS names in GRANT statements. Instead you'll be restricted to using IP addresses.  
  8.   
  9. 2.1) or put in my.ini :  
  10.   
  11. [mysqld]  
  12. skip-name-resolve  
  13. I'd recommend (1) if you can.  
  14.   
  15. Hope this helps.  
然后也确实解决了这个问题。记录一下
 
 

 
 

Tags: mysql

宁可错杀3000,不可放走一个

看到这个,应该明白了吧
 

 delete from sablog_comments where visible =0 and content REGEXP '^[0-9a-zA-Z]{6} ' 

 
定期执行一下吧。NND

apache 2.2升到2.4的小坑

 2.2升到2.4的小坑应该就出在权限上了

具体查看:https://httpd.apache.org/docs/current/upgrading.html
即,凡是遇到Order allow,deny allow from all等与Order相关的,最好看一下上面的链接。
比如我们用rewrite的时候,都是
XML/HTML代码
  1. Options Indexes FollowSymLinks 
  2. AllowOverride All  
  3. Order allow,deny  
  4. allow from all  

在2.4下面,上面的代码不报错,但不起作用。如果你的目录下面有.htaccess文件,那么,网站是打不开的,上面的代码改成

XML/HTML代码
  1. <Directory /var/www/>  
  2.     Options Indexes FollowSymLinks  
  3.     AllowOverride All  
  4.     Require all granted  
  5. </Directory>  
OK,再次打开就正常了