LAMP搭建24:MySQL備份與恢複

來源:互聯網
上載者:User

標籤:lamp   備份   mysql   恢複   

使用mysqldump工具,以root使用者身份,密碼aming.com備份discuz資料庫到/data/discuz.sql

[[email protected] mysql]# mkdir -p /data/bak/mysql/

[[email protected] mysql]# mysqldump -uroot -p123456 discuz > /data/bak/mysql/discuz.sql

查看備份的內容

[[email protected] mysql]# head /data/bak/mysql/discuz.sql

-- MySQL dump 10.13  Distrib 5.1.49, for pc-linux-gnu (i686)

--

-- Host: localhost    Database: discuz

-- ------------------------------------------------------

-- Server version       5.1.49

/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;

/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;

/*!40101 SET @[email protected]@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

……

備份是按建立庫,建立表,插入資料的規律進行的,所以可以恢複。如果我們不小心刪了論壇的資料庫,我們的論壇就不能使用了。

mysql> drop database discuz;

Query OK, 297 rows affected (0.04 sec)

650) this.width=650;" src="https://s4.51cto.com/wyfs02/M00/8C/DF/wKioL1h8hs7TQHvQAAFkeg80zzk710.png-wh_500x0-wm_3-wmp_4-s_3427367125.png" title="1.png" alt="wKioL1h8hs7TQHvQAAFkeg80zzk710.png-wh_50" />

恢複資料庫之後,論壇又可以使用了。

mysql> create database discuz;

Query OK, 1 row affected (0.00 sec)

[[email protected] discuz]# mysql -uroot -p123456 discuz < /data/bak/mysql/discuz.sql

650) this.width=650;" src="https://s2.51cto.com/wyfs02/M00/8C/E3/wKiom1h8hufz10RnAAE0SiwAJGQ068.png-wh_500x0-wm_3-wmp_4-s_1728712059.png" title="2.png" alt="wKiom1h8hufz10RnAAE0SiwAJGQ068.png-wh_50" />

備份一個表,需要加表名

[[email protected] discuz]# mysqldump -uroot -p123456 mysql user > /data/bak/mysql/user.sql

恢複一個表,不需要加表名

[[email protected] discuz]# mysql -uroot -p123456 mysql < /data/bak/mysql/user.sql

為了避免備份和恢複字元集不一致,我們可以指定字元集備份和恢複

[[email protected] discuz]# mysqldump -uroot -p123456 --default-character-set=gbk mysql user > /data/bak/mysql/user.sql

[[email protected] discuz]# mysql -uroot -p123456 --default-character-set=gbk mysql < /data/bak/mysql/user.sql


LAMP搭建24:MySQL備份與恢複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.