从年后来一直忙着迁移机房,广州机房已经迁移完了,珠海IDC也快差不多了,最迟4月底迁移完毕,这周主要迁移两套EMC储存,有几台内网的数据库服务器挂载的储存空间,需要把储存上的数据库迁移服务器上,下面记录具体迁移步骤:

一、环境:

1.原数据库服务器:172.28.29.21(挂载EMC到/sandata目录)

2.先数据库服务器:10.20.220.107

二、具体思路:

1.在10.20.220.107上做NFS,把/data/db给172.28.29.21挂载

2.在172.28.29.21上把10.20.220.107的/data/db挂载到/data/db

3.在172.28.29.21上把/sandata目录下的mysql数据库目录DB下的所有文件copy到/data/db下

4.在10.20.220.107上安装mysql数据库,把数据库路径指到/data/db

5.测试

三、实施步骤

1.前面三步很简单了,在这里就不说了,下面我们安装mysql数据库

a.先安装ncurses-devel

[root@localhost ~]# yum install ncurses-devel

b.安装mysql

[root@localhost ~]# useradd mysql -s /sbin/nologin

[root@localhost ~]# tar -zxvf mysql-5.1.54.tar.gz
[root@localhost ~]# cd mysql-5.1.54

[root@localhost mysql-5.1.54]# ./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --with-extra-charsets=all --with-charset=utf8 --with-unix-socket-path=/usr/local/mysql/var/mysql.sock --enable-thread-safe-client --with-plugins=innobase

注意:这步可能报这个错误:

config.status: executing libtool commands
/bin/rm: cannot remove `libtoolT': No such file or directory
config.status: executing default commands
解决办法:

在执行./configure 之前,先执行:
# autoreconf --force --install
# libtoolize --automake --force
# automake --force --add-missing

再次执行:

[root@localhost mysql-5.1.54]# ./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --with-extra-charsets=all --with-charset=utf8 --with-unix-socket-path=/usr/local/mysql/var/mysql.sock --enable-thread-safe-client --with-plugins=innobase

[root@localhost mysql-5.1.54]# make && make install

#copy一个my.cnf文件到/etc下,后面我会把内容贴出来的

[root@localhost data]# chown mysql /data/db

[root@localhost db]# chmod 777 /data/db

[root@localhost ~]# /usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/data/db

[root@localhost db]# /usr/local/mysql/bin/mysqld_safe &

至此,mysql安装完毕

#给root设置一密码:

[root@localhost db]# /usr/local/mysql/bin/mysql -uroot

mysql> update user set password=password('asdf123!') where User='root';

mysql> flush privileges;

#添加远程用户:

mysql> grant all privileges on *.* to admin@'%' identified by 'asdf123!'with grant option;

mysql> flush privileges;

# 调整lib库路径、MySQL程序的执行路径

[root@localhost db]# vi /etc/ld.so.conf

加入“/usr/local/mysql/mysql”

[root@localhost db]# ldconfig

vi  /etc/profile

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

上面加入:
PATH=$PATH:/usr/local/mysql/bin

刷新:
 source /etc/profile

mysql添加的系统服务中

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld

[root@localhost mysql-5.1.54]# chown mysql /etc/init.d/mysqld
[root@localhost mysql-5.1.54]# chmod 777 /etc/init.d/mysqld

[root@localhost mysql-5.1.54]# service mysqld start
Starting MySQL. SUCCESS!

测试,看一下,172.28.29.22上库是否正确识别

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| datacenter         |
| mysql              |
| navy               |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> show tables;
+----------------------+
| Tables_in_datacenter |
+----------------------+
| duba                 |
| weishi               |
+----------------------+
2 rows in set (0.00 sec)

mysql>

OK,一切正常。