您好,登錄后才能下訂單哦!
環(huán)境
[root@db01 ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@db01 ~]# uname -r
2.6.32-573.el6.x86_64
[root@db01 ~]# uname -m
x86_64
創(chuàng)建軟件下載目錄
[root@db01 ~]# mkdir /home/oldboy/tools
創(chuàng)建軟件安裝目錄
[root@db01 ~]# mkdir /application/
下載上傳命令
[root@db01 ~]# yum install -y lrzsz
上傳MySQL安裝包
[root@db01 ~]# cd /home/oldboy/tools/
[root@db01 tools]# rz -y
(提前下載好MySQL5.5.49的壓縮包)
查看
[root@db01 tools]# ls -lh
total 178M
-rw-r--r-- 1 root root 178M May 16 23:19 mysql-5.5.49-linux2.6-x86_64.tar.gz
創(chuàng)建mysql用戶
[root@db01 tools]# useradd -s /sbin/nologin mysql -M
檢查
[root@db01 tools]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
解壓
[root@db01 tools]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz
移動并重命名
[root@db01 tools]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49
創(chuàng)建軟鏈接
[root@db01 tools]# ln -s /application/mysql-5.5.49/ /application/mysql
檢查
[root@db01 tools]# ls /application/mysql
bin docs lib README sql-bench
COPYING include man scripts support-files
data INSTALL-BINARY mysql-test share
切換到MySQL目錄
[root@db01 tools]# cd /application/mysql
授權(quán)
[root@db01 mysql]# chown -R mysql.mysql /application/mysql/
初始化
[root@db01 mysql]# ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/
[root@db01 mysql]# ll -ld /tmp/
drwxrwxrwt. 4 root root 4096 May 18 01:12 /tmp/
[root@db01 mysql]# ll data/
total 12
drwx------ 2 mysql root 4096 May 18 01:12 mysql
drwx------ 2 mysql mysql 4096 May 18 01:12 performance_schema
drwxr-xr-x 2 mysql mysql 4096 May 18 01:07 test
修改啟動腳本文件路徑
[root@db01 mysql]# cd bin/
[root@db01 bin]# cp mysqld_safe{,.ori}
進行替換,因為二進制文件默認(rèn)目錄不是我們上傳放軟件/application/下面的
[root@db01 bin]# sed -i 's#/usr/local#/application/#g' mysqld_safe
拷貝到/etc下
[root@db01 mysql]# cd ../
[root@db01 mysql]# \cp support-files/my-small.cnf /etc/my.cnf
[root@db01 mysql]# /application/mysql/bin/mysqld_safe --user=mysql & #(時間有點久,估計一分鐘)
[root@db01 mysql]# lsof -i :3306
[root@db01 mysql]# /application/mysql/bin/mysql
設(shè)置全局變量
[root@db01 mysql]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@db01 mysql]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@db01 mysql]# . /etc/profile
[root@db01 mysql]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
設(shè)置MySQL啟動腳本
[root@db01 mysql]# cd support-files/
[root@db01 support-files]# cp mysql.server{,.ori}
[root@db01 support-files]# cd ..
[root@db01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@db01 mysql]# chmod +x /etc/init.d/mysqld
[root@db01 mysql]# sed -i 's#/usr/local/#/application/#g' /etc/init.d/mysqld
設(shè)置MySQL開機自啟動
[root@db01 mysql]# chkconfig --add mysqld
[root@db01 mysql]# chkconfig mysqld on
[root@db01 mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
提示:也可以將啟動命令/etc/init.d/mysqld start 放到/etc/rc.local里面。
把wordpress數(shù)據(jù)庫遷移到后端數(shù)據(jù)庫中或者說數(shù)據(jù)庫的遷移
1.在10.0.0.8 上操作
①.導(dǎo)出web10.0.0.8 數(shù)據(jù)庫中的wordpress數(shù)據(jù)庫
[root@web01 ~]# mysqldump -uroot -poldboy123 wordpress -B|gzip >bak.sql.gz
[root@web01 ~]# ls
anaconda-ks.cfg bak.sql.gz install.log install.log.syslog nginx-1.6.3.tar.gz
[root@web01 ~]#
②.把數(shù)據(jù)備份的腳本傳送到后臺數(shù)據(jù)庫10.0.0.51的文件系統(tǒng)中,目的還原,增加至數(shù)據(jù)庫
[root@web01 ~]# scp bak.sql.gz root@10.0.0.51:/tmp
The authenticity of host '10.0.0.51 (10.0.0.51)' can't be established.
RSA key fingerprint is 61:c1:8c:77:39:33:91:47:5c:4c:b5:0f:5a:aa:7d:be.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.51' (RSA) to the list of known hosts.
root@10.0.0.51's password:
bak.sql.gz 100% 121KB 121.2KB/s 00:00
[root@web01 ~]#
③更改訪問數(shù)據(jù)庫的配置文件
[root@web01 blog]# cd /application/nginx/html/blog/
[root@web01 blog]# vim wp-config.php
define('DB_HOST', '172.16.1.51');
2.在10.0.0.51上操作
解壓
[root@db01 mysql]# cd /tmp/
[root@db01 tmp]# gzip -d bak.sql.gz
導(dǎo)入數(shù)據(jù)
[root@db01 tmp]# mysql -uroot -poldboy123</tmp/bak.sql
[root@db01 tmp]#
在數(shù)據(jù)庫中授權(quán)
[root@db01 tmp]# mysql -uroot -poldboy123
mysql> grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql>
3關(guān)閉10.0.0.8的數(shù)據(jù)庫
[root@web01 blog]# /etc/init.d/mysqld stop
[root@web01 blog]# chkconfig mysqld off
[root@web01 blog]# chkconfig --list mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@web01 blog]#
4測試:
http://blog.etiantian.org/wp-admin/edit.php
在web界面發(fā)表一篇文章,然后去172.16.1.51這臺服務(wù)器去測試數(shù)據(jù)
mysql> select * from old_posts \G;
wordpress圖片的分離,將圖片分離到NFS上
1.建立NFS掛載點,并授權(quán)
[root@nfs01 ~]# cat /etc/exports
/data/upload 172.16.1.0/24(rw,sync,all_squash,anonuid=500,anongid=500)
[root@nfs01 ~]# mkdir -p /data/upload
[root@nfs01 ~]# useradd -u 506 -s /sbin/nologin www -M
[root@nfs01 ~]# id www
uid=506(www) gid=506(www) groups=506(www)
[root@nfs01 ~]# chown -R www.www /data/upload
[root@nfs01 ~]#
2.本分本機的數(shù)據(jù)防止中間出現(xiàn)錯誤
[root@web01 tmp]# cd /application/nginx/html/blog/wp-content/uploads/
[root@web01 uploads]# pwd
/application/nginx/html/blog/wp-content/uploads
[root@web01 uploads]# cp -a 2016 /tmp/
3.本機掛載
[root@web01 uploads]# mount -t nfs 172.16.1.31:/data/upload /application/nginx/html/blog/wp-content/uploads
[root@web01 uploads]# df -h /application/nginx/html/blog/wp-content/uploads
Filesystem Size Used Avail Use% Mounted on
172.16.1.31:/data/upload
6.9G 1.5G 5.1G 22% /application/nginx-1.6.3/html/blog/wp-content/uploads
[root@web01 uploads]#
4.把原來的數(shù)據(jù)遷移回來
[root@web01 tmp]# \cp -a /tmp/2016 /application/nginx/html/blog/wp-content/uploads/
反思:NFS共享目錄一定要和nginx目錄用戶的權(quán)限一致 ,在前期application/nginx/對這個授予了nginx的權(quán)限
否則無法寫入
關(guān)于wordpress的反思
1.nginx存儲目錄的權(quán)限要和NFS遠程允許掛載的權(quán)限一致
2.所有的服務(wù)都應(yīng)該是開機啟動
3.遷移數(shù)據(jù)首先要備份數(shù)據(jù)
4.NFS掛載端的開機掛載應(yīng)該放在/etc/rc.lcoal中,不能放在/etc/fstab中
1.登錄數(shù)據(jù)庫
[root@web01 data]# mysql -uroot -p
2.更改已知用戶的密碼
[root@web01 ~]# mysqladmin -uroot -p123456 password "oldboy"
3.初始化root的密碼
[root@web01 ~]# mysqladmin -uroot password "123456"
4.查看數(shù)據(jù)庫
mysql> show databses;
5.使用數(shù)據(jù)庫
mysql> use mysql;
Database changed
mysql>
6.查看數(shù)據(jù)庫的表
mysql> show tables;
7.查看數(shù)據(jù)表的結(jié)構(gòu)
mysql> describe user;
8.從表中查找字段(此處查詢的字段不區(qū)分大小寫)
mysql> select Host,User from user; #直接查表
mysql> select host,user from mysql.user; #從哪個庫的哪一個表
9.刪除庫中的數(shù)據(jù)(use數(shù)據(jù)庫中的 用戶)
mysql> drop user "sanlang"@"10.0.0.8";
或者:
mysql>delete from mysql.user where user="sanlang" and host="110.0.0.8";
10.查看當(dāng)前的用戶
mysql> select user();
11.查看當(dāng)前所在的數(shù)據(jù)庫
mysql> select database();
12.處理完用戶要執(zhí)行的命令
mysql> flush privileges;
13.導(dǎo)出數(shù)據(jù)庫
[root@web01 ]#mysqldump -uroot -poldboy123 wordexpress -B|gzip >bak.sql.gz
14.把數(shù)據(jù)庫腳本導(dǎo)入
[root@web01 ]#mysql -uroot -poldboy123</tm/bak.sql
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。