Linux CentOS 伺服器搭建 《四》

2021-09-23 21:52:04 字數 4120 閱讀 2904

既然tomcat,弄好了,資料庫安裝好了。我們考慮考慮下。今天帶給大家是,

資料庫的還原備份:

備份開始:

登入開始:  

1

mysql -u root -p

建立乙個測試用的資料庫test並建立一張表test:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

#建立新的測試資料庫

create database test;

use test;

create table test (idint);

insert into test values(1);

insert into test values(2);

insert into test values(3);

insert into test values(4);

insert into test values(5);

select * from test;

然後備份test的整個資料庫

vi /usr/local/bakcupmysql/backup_test.sh

1

2

3

4

5

6

7

8

9

#!/bin/sh

date_str=`date +%y%m%d`

cd /var/lib/mysql

mysqldump -h localhost -u root --password=123456-r -e -e \

--max_allowed_packet=1048576--net_buffer_length=16384test\

| gzip > /usr/local/bakcupmysql/backuptest_$date_str.sql.gz

echo"database backup success!"

//建立成功後必須先看引數,根據引數修改剛剛的檔案。

1

2

3

4

5

6

7

8

9

10

11

12

max_allowed_packet 和 net_buffer_length 這兩個引數起著決定性作用,速度差別幾百上千倍

其原理是合併多條資料成為乙個 sql 插入語句。

匯出時候注意點:

第一:

-e 使用包括幾個values列表的多行insert語法;

--max_allowed_packet=*** 客戶端/伺服器之間通訊的快取區的最大大小;

--net_buffer_length=*** tcp/ip和套接字通訊緩衝區大小,建立長度達net_buffer_length的行。

注意:max_allowed_packet和net_buffer_length不能比目標資料庫的設定數值 大,否則可能出錯。

首先確定目標庫的引數值

mysql -u root -p

mysql>show variables like'max_allowed_packet';

mysql>show variables like'net_buffer_length';

第二:/var/lib/mysql   這個是資料庫的路徑

/usr/local/bakcupmysql/   這個是備份的路徑

#執行1

sh /usr/local/bakcupmysql/backup_test.sh

這樣輕輕鬆鬆地,把資料庫的給備份好了。你可以去 /usr/local/bakcupmysql/ 看看 多出了乙個 dsideal_test_20131016.sql.gz 的檔案。

下面開始還原

從壓縮檔案直接恢復:

cd 到你要備份的資料庫的路徑

1

gzip < dsideal_test_20130405.sql.gz | mysqldump -u root -p test

附加一些知識吧

crontab -e

在下面新增

1

1013* * * root /usr/local/backup_test.sh

1#表示每天3點鐘執行備份

定時器一些知識

crontab -e

* * * /var/proftpd_data/backup/bin/mysqlfullbackup.sh

* * * /var/proftpd_data/backup/bin/ftpdownload.sh

前五個欄位的整數取值範圍及意義是:

0~59 表示分

1~23 表示小時

1~31 表示日

1~12 表示月份

0~6 表示星期(其中0表示星期日)

在介紹下例子。我剛剛弄的

1.首先我們將要匯入到資料庫中的.sql檔案放到你知道目錄下,這樣比較方便

2.進入mysql;mysql>create database netcredit;

3.使用新建立的資料庫 mysql>use netcredit;

4.匯入檔案: mysql>source 匯入的檔名; 

5.如果沒有提示錯誤資訊提示,我們可以通過show tables;指令可以看到新建立的netcredit資料庫裡面已經匯入了剛netcredit資料庫裡的內容。

1

windows git daemon 伺服器搭建

安裝git 使用不再贅 在資料夾repo 中執行git init新建git倉庫 在 repo目錄下執行git config local receive.denycurrentbranch updateinstead執行git config global sendpack.sideband false...

Linux Centos伺服器筆記

1.call to undefined function mcrypt module open yum install php mcrypt libmcrypt libmcrypt devel service php fpm restart2.thinkcmf後台驗證碼無法顯示,出現call to ...

自搭ngrok伺服器

在阿里雲伺服器自己搭 ngrok 的伺服器,步驟基本跟著 1,2 一步步來,本人需要用到 這裡僅提幾點注意 我那個阿里雲伺服器有個網域名稱,在管理頁可以看的,生成證書時設定export ngrok domain 那個網域名稱 就是用這個網域名稱,後面 ngrokd 的執行引數 client 端的配置...