Blog

  • mysqldump备份时出现问题

    使用mysqldump备份时,–opt表示采用优化(Optimize)方式

    mysqldump --opt -uroot -ppasswd c14sql >c14sql.sql

    出现错误

    mysqldump: Got error: 145: Table './c14sql/is_stats' is marked as crashed and should be repaired when using LOCK TABLES

    解决办法1,用myisamchk

    myisamchk -c -r /var/lib/mysql/c14sql/is_stats.MYI

    解决办法2,进入mysql>(暂未测试)

    mysql> repair table is_stats;

    检测一下

    mysql> check tables is_stats;

    没问题的话再备份就没有问题了

    ps:

    mysqldump 导出表结构 –no-data flag to make it only export structure

    mysqldump -u jira -p -h 192.168.9.11 jira6 --no-data > jira6.nodata.sql

     

  • tar命令使用的几个例子

    常用命令:

    -c 创建包
    -x 解包
    -t 列出包中的内容
    -r 增加文件到指定包中
    -u 更新包中的文件

    可选命令:

    -j 使用bzip2
    -z 使用gzip
    -Z 使用compress
    -f  后面跟包的文件名
    -v  显示执行过程
    -C 指定解包后的路径

    例一:tar打包文件(并用gzip压缩)

    tar vczf a.tar.gz hello

    例二:tar不解压 查看目录结构

    tar tvf a.tar.gz | grep ^d

    例三:除了/var/www/clients这个文件夹,打包/var/www中的所有文件和文件夹

    tar vczf www.tar.gz /var/www/ --exclude=clients

    如果要排除多个可以一直加

    --exclude dir1 --exclude a.log --exclude *.jpg

    例四:解压tar.bz2文件

    首先:
    bzip2 -d mono-2.10.tar.bz2
    执行完发现只有一个mono-2.10.tar
    现在再执行
    tar -xvf mono-2.10.tar
    就得到了mono-2.10文件夹

    或直接使用

    tar jxf mono-2.10.tar.bz2

    例五:将多个文件夹打包

    tar -czf abc.tar.gz /home/a /home/b /home/c

    例六:分卷压缩及合并,Linux下备份网站数据,由于目录abc打包成一个文件会比较大,所以想分卷压缩成每个100M的文件,方便下载。

    分卷压缩,使用tar+split组合,进入目录上级目录,执行:
    tar cvzf - abc | split -b 100m
    会产生以x开头的文件,然后把x开头的文件传输到目标地
    合并
    cat x* > abc.tar.gz
    解压
    tar xvzf abc.tar.gz

    例七:解压tar文件

    file命令查看结果是POSIX tar archive格式,使用命令

    tar xvf xxx.tar

    例八:使用tar打包时不使用绝对路径

    如:tar vczf jpuyy.tar.gz /home/jpuyy/

    会提示”tar: Removing leading `/’ from member names”,解压时会在当前目录解压成home/jpuyy。如果想要解压到/home/jpuyy,则使用-C /指令,即

    tar vxzf jpuyy.tar.gz -C /

    例九:提取tar.gz中的指定一个文件,先找到这个文件

    tar tvf redis-2.6.14.tar.gz | grep redis_init_script
    -rwxrwxr-x root/root 1098 2013-06-20 16:36 redis-2.6.14/utils/redis_init_script

    然后执行

    tar xzf redis-2.6.14.tar.gz redis-2.6.14/utils/redis_init_script

    得到想要指定文件。

    例九:只将目录内部的文件打包,不包括顶层目录

    tar czf workspace.tar.gz -C /path/to/workspace .
    

    参考:http://xiaobin.net/200911/tar-removing-leading-slash-from-member-name/

    题外话

    使用gzip压缩

    gzip jpuyy-backup-20121212.sql

    使用gzip解压

    gzip -d jpuyy-backup-20121212.sql.gz
  • cut使用的几个例子

    cut用来截取字符串

    例一:

    以’>’为分段,截取第2段

    如ls -l我的配置文件得到它的真实路径,看到输出的可以以’>’分隔

    jpuyy@www:~$ ls -l jpuyy.com.conf
    lrwxrwxrwx 1 root root 52 2012-03-08 18:03 jpuyy.com.conf ->../sites-available/jpuyy.com.conf

    则执行(-d代表分隔符,可任意发挥,默认TAB;-f代表是第几段,后面可跟子参数N,N-,N-M,-M)

    jpuyy@www:~$ ls -l jpuyy.com.conf | cut -d'>' -f 2
     ../sites-available/jpuyy.com.conf

    例二:取得文件中每行中特定的几个字符

    截取m-n之间字符,语法:

    cut -c m-n filename

    -c后面可跟子参数有N,N-,N-M,-M

    例子:

    cut -c 3-5 /etc/passwd
    
  • du命令使用的例子

    du–用来计算文件占用空间的命令

    例1:显示当前目录下的各文件夹大小(并不显示单个文件的大小),最后一行显示的是当前目录的总大小

    du -h --max-depth=1
    4.0K ./hob
    232M ./chan
    4.0K ./1d4
    291M ./ngjewel
    4.0K ./gzjul
    4.0K ./lifi
    728M .

    例2:显示 work/testing下的目录大小

    # du -h --max-depth=1 work/testing
    27M work/testing/logs
    35M work/testing

    显示 work/testing/下面所有文件和目录大小

    du -h --max-depth=1 work/testing/*
    8.0K work/testing/func.php
    27M work/testing/logs
    8.1M work/testing/nohup.out

    例3:遍历显示子目录及子文件的大小

    du -ha
  • mysql(已知旧密码)修改密码的两种方法

    http://www.cyberciti.biz/faq/mysql-change-root-password/

    这里的前提是你能登的进mysql

    方法一:用mysqladmin命令修改root密码

    如果你装mysql的时候用的空密码,现在要设定一个初始密码,那么执行:If you have never set a root password for MySQL server, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:

    $ mysqladmin -u root password NEWPASSWORD

    你想要更新密码,用如下命令,However, if you want to change (or update) a root password, then you need to use the following command:

    $ mysqladmin -u root -p'oldpassword' password newpass

    例如,旧密码是abc,新密码是123456,则输入,For example, If the old password is abc, you can set the new password to 123456, enter:

    $ mysqladmin -u root -p'abc' password '123456'

    更改其他用户的密码,Change MySQL password for other users

    如更改普通用户密码,用如下命令,To change a normal user password you need to type (let us assume you would like to change password for user vivek) the following command:

    $ mysqladmin -u vivek -p oldpassword password newpass

    方法二:用mysql的sql语言来更改root密码

    Changing MySQL root user password using MySQL sql command

    在mysql数据库中保存了root的密码,This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:

    1)用root登陆 Login to mysql server, type the following command at shell prompt:

    $ mysql -u root -p

    2) 切换到mysql数据库,Use mysql database (type command at mysql> prompt):

    mysql> use mysql;

    3) 更新vivek的密码Change password for user vivek, enter:

    mysql> update user set password=PASSWORD("NEWPASSWORD") where User='vivek';

    4) 最后刷新权限,Finally, reload the privileges:

    mysql> flush privileges;
    mysql> quit

    后一种方法可以用在php,python和perl中
    The last method can be used with PHP, Python or Perl scripting mysql API.

    2014-01-09更新:

    执行SET PASSWORD命令,更改 ‘jpuyy’@’localhost’

    SET PASSWORD FOR 'jpuyy'@'localhost' = PASSWORD('password');

    如果是更改自己的密码,可省略for语句

    SET PASSWORD = PASSWORD('password');

    还可以使用GRANT USAGE(在*.*)来指定某个账号的密码而不影响账户当前的权限。

    GRANT USAGE ON *.* TO 'jpuyy'@'localhost' IDENTIFIED BY 'password';
  • 禁用iredmail的greylisting,重启的policyd

    打开/etc/policyd.conf

    ##################################################################
    # GREYLISTING (functional) #
    ##################################################################
    #
    # enable greylisting default: on
    #
    # whether greylisting should be enabled or disabled.
    #
    # 1=on 0=off
    GREYLISTING=1

    把上面的1改成0以后

    /etc/init.d/policyd restart

    但是这样十分容易收到垃圾邮件,鱼和熊掌不可兼得。