月度归档:2010年11月

vi,替换

vi/vim 中可以使用 :s 命令来替换字符串§以前只会使用一种格式来全文替换,今天发现该命令有很多种写法,记录几种在此,方便以后查询§

:s/vivian/sky/ 替换当前行第一个 vivian 为 sky
:s/vivian/sky/g 替换当前行所有 vivian 为 sky
:n,$s/vivian/sky/ 替换第 n 行开始到最后一行中每一行的第一个 vivian 为 sky
:n,$s/vivian/sky/g 替换第 n 行开始到最后一行中每一行所有 vivian 为 sky
n 为数字,若 n 为 .,表示从当前行开始到最后一行
继续阅读

mysql查看表的大小

如果想知道MySQL数据库中每个表占用的空间、表记录的行数的话,可以打开MySQL的 information_schema 数据库。在该库中有一个 TABLES 表,这个表主要字段分别是:

TABLE_SCHEMA : 数据库名
TABLE_NAME:表名
ENGINE:所使用的存储引擎
TABLES_ROWS:记录数
DATA_LENGTH:数据大小
INDEX_LENGTH:索引大小

其他字段请参考MySQL的手册,我们只需要了解这几个就足够了。

所以要知道一个表占用空间的大小,那就相当于是 数据大小 + 索引大小 即可。

SQL:

SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS FROM TABLES WHERE TABLE_SCHEMA=’数据库名’ AND TABLE_NAME=’表名’

touch 更改文件时间,创建时间,修改时间等。

[root@server1 /]# stat /bin/bash

File: `/bin/bash’

Size: 722684          Blocks: 1432       IO Block: 4096   regular file

Device: 802h/2050d      Inode: 3524863     Links: 1

Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2008-08-18 13:15:01.000000000 +0800

Modify: 2006-07-12 15:11:53.000000000 +0800

Change: 2008-05-14 12:01:18.000000000 +0800

-------------------------------------------

Here are the definitions of the different UNIX time information on a file with how they are typically referred to in  man pages and the option to list the particular time with the  ls  command.

Access Time | atime | -ul
              This is the time that the file was last accessed, read or written to.
              访问文件

Modify Time | mtime | -l
      
This is the time that the inode information (permissions, name, etc., the metadata, as it were) was last modified
              改文件内容

Change Time | ctime | -cl
              This is the last time the actual contents of the file were last modified.
              改文件名,改文件内容,改文件权限,所有者,所属组

shell的for循环

关于shell中的for循环用法很多,一直想总结一下,今天网上看到上一篇关于for循环用法的总结,感觉很全面,所以就转过来研究研究,嘿嘿…

1、 for((i=1;i<=10;i++));do echo $(expr $i \* 4);done
2、在shell中常用的是 for i in $(seq 10)
3、for i in `ls`

4、for i in ${arr[@]}  
5、for i in $* ; do
6、for File in /proc/sys/net/ipv4/conf/*/accept_redirects; do
7、for i in f1 f2 f3 ;do
8、for i in *.txt
9、for i in $(ls *.txt)
for in语句与` `和$( )合用,利用` `或$( )的将多行合为一行的缺陷,实际是合为一个字符串数组
10、LIST=”rootfs usr data data2″
for d in $LIST; do
    用for in语句自动对字符串按空格遍历的特性,对多个目录遍历
11、for i in {1..10}
12、for i in stringchar {1..10}
13、awk ‘BEGIN{for(i=1; i<=10; i++) print i}’

注意:AWK中的for循环写法和C语言一样的

使用yum 更新as4 update8,使用的是163的源

万网太恶心,装centos还要收费,默认的是as4.8,NND

只能使用以下的山寨方式更新。笔记之

as4 update8       
yum 安装
wget http://yum.baseurl.org/download/2.4/yum-2.4.3-1.src.rpm
rpmbuild –rebuild yum*.src.rpm
cd /usr/src/redhat/RPMS/noarch
rpm -ivh yum-2.4.3-1.noarch.rpm
vi /etc/yum.conf
加入以下内容:

[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
#[base]
#name=Red Hat Linux $releasever – $basearch – Base
#baseurl=http://mirror.dulug.duke.edu/pub/yum-repository/redhat/$releasever/$basearch/
[base]
name=Red Hat Linux $releasever – $basearch – Base
baseurl=http://mirrors.163.com/centos/4.8/os/i386/

以上使用163的源

保存后
yum update
即可

不停机做mysql主从

2.1:在A机器上mysqldump -uroot -p123 -E -R –master-data databasename>c:\0803.sql
得到备份文件
2.2:到B机器上还原mysql -uroot -p123 databasename<c:\0803.sql
2.3:用MORE命令,得到0803.SQL里的change master to 命令里的参数
2.4:在B里,STOP SLAVE,再CHANGE MASTER TO,再START SLAVE

g++: yes: No such file or directory mysql编译出错

configure 没问题

make时出错,最后有如下错误信息

g++: yes: No such file or directory

mysql官方说,configure时可以去掉–with-mysqld-libs,或者指定相关的路径什么的,我去掉后还是出错

后来去掉–with-named-curses-libs选项后,正常了