服务器迁移日记

this blog trace the process of transmit the server
1. backup mysql database
    a. 如何看当前机器是否安装mysql
    b. 查看mysql 数据 安装位置
        一般mysql安装的数据,在/var/lib/mysql下,可以通过
        show variables like 'datadir' 来得到
        这里有一篇关于如何迁移data的文章
        http://developer.spikesource.com/wiki/index.php/How_to_change_the_mysql_database_location
    c. 通过man 看linux 的menu, 方法man <commend name>
    d. 通过du 看目录的大小。
        du 列出当前目录下所有的文件、子目录及各自的大小,最后一个是当前目录所占用总空间。
        du -s 只列出当前目录所占用的空间。
        du -sh 以列出k、M字节为单位的空间。
    e. mysql> show databases; show tables;
    f. 寻找备份文件应存放的地点, 通过df 来找到大的mount,df . 得到当前目录相关mount信息
   
    g. 备份命令
    #mysqldump -u root -p tm > tm_050519.sql
    #mysqldump -u root -p tm | gzip > tm_050519.sql.gz
   
    回复
    #mysql -u root -p tm < tm_050519.sql
    #gzip < tm_050519.sql.gz | mysql -u root -p tm
   
    http://tech.sina.com.cn/s/2008-09-11/08072450294.shtml
    http://blog.chinaunix.net/u3/112582/showart_2199885.html
    http://tech.ddvip.com/2007-10/119362784036619.html
    http://blog.csdn.net/bxbx258/archive/2008/09/18/2945832.aspx
   
2. 还原数据库
    a.安装 mysql
    yum install mysql
    yum install mysql-server
    yum install mysql-devel
    chgrp -R mysql /var/lib/mysql
    chmod -R 770 /var/lib/mysql
    /sbin/service mysqld start

    b.更改root密码
    mysqladmin -uroot -p password <newpwd>

    c.解压 tar zxvf xxxx.tar.gz
    http://blog.chinaunix.net/u1/57112/showart.php?id=443575
   
3.    其他常用mysql指令
/sbin/service mysqld start

# To Stop MySQL Server
/sbin/service mysqld stop

# To Restart MySQL Server
/sbin/service mysqld restart


4. 如何查看一个用户属于哪个组(group)的?
   a.groups maf
    1)与用户(user)相关的配置文件;

    /etc/passwd 注:用户(user)的配置文件;
    /etc/shadow 注:用户(user)影子口令文件;


    2)与用户组(group)相关的配置文件;

    /etc/group 注:用户组(group)配置文件;
    /etc/gshadow 注:用户组(group)的影子文件;
   
   
    b.管理用户组(group)的工具或命令;
    groupadd  注:添加用户组;
    groupdel         注:删除用户组;
    groupmod        注:修改用户组信息
    groups     注:显示用户所属的用户组
    grpck
    grpconv   注:通过/etc/group和/etc/gshadow 的文件内容来同步或创建/etc/gshadow ,如果/etc/gshadow 不存在则创建;
    grpunconv   注:通过/etc/group 和/etc/gshadow 文件内容来同步或创建/etc/group ,然后删除gshadow文件;\
   
    http://fedora.linuxsir.org/main/?q=node/91
   
5. optimize table
http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html

OPTIMIZE NO_WRITE_TO_BINLOG TABLE dcache

Mysql doesnt reduce the size of ibata1. Ever. Even if you use optimize table to free the space used from deleted records. It will reuse it later.
An alternative is to configure the server to use innodb_file_per_table. But this will require a backup, drop database and restore. The positive side is that the .ibd file for the table is reduced after a optimize table.

http://stackoverflow.com/questions/1270944/mysql-innodb-not-releasing-disk-space-after-deleting-data-rows-from-table

你可能感兴趣的:(sql,mysql,PHP,SQL Server,配置管理)