天天看點

CentOS5.6下mysql遷移

從年後來一直忙着遷移機房,廣州機房已經遷移完了,珠海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]# 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;

#調整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,一切正常。