<!DOCTYPE html>
	<html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
	<head>
<title>Sao Lưu và Khôi Phục Cơ Sở Dữ Liệu MySQL bằng Mysqldump</title>
<meta name="description" content="Sao Lưu và Khôi Phục Cơ Sở Dữ Liệu MySQL bằng Mysqldump - Savefile - Tin Tức -...">
<meta name="author" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG">
<meta name="copyright" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG [webmaster@tinhocdct.xyz]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Sao Lưu và Khôi Phục Cơ Sở Dữ Liệu MySQL bằng Mysqldump">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;tinhocdct.xyz&#x002F;savefile&#x002F;tin-cong-nghe&#x002F;sao-luu-va-khoi-phuc-co-so-du-lieu-mysql-bang-mysqldump-547.html">
<meta property="og:site_name" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG">
<meta property="og:url" content="https://tinhocdct.xyz/tin-cong-nghe/sao-luu-va-khoi-phuc-co-so-du-lieu-mysql-bang-mysqldump-547.html">
<link rel="shortcut icon" href="https://tinhocdct.xyz/favicon.ico">
<link rel="canonical" href="https://tinhocdct.xyz/tin-cong-nghe/sao-luu-va-khoi-phuc-co-so-du-lieu-mysql-bang-mysqldump-547.html">
<link rel="alternate" href="https://tinhocdct.xyz/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tin-tuc/" title="Tin Tức - TIN TỨC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/thong-cao-bao-chi/" title="Tin Tức - THÔNG BÁO" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/ban-tin-noi-bo/" title="Tin Tức - BẢN TIN NỘI BỘ" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tin-cong-nghe/" title="Tin Tức - CÔNG NGHỆ - KHOA HỌC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/thu-thuat/" title="Tin Tức - THỦ THUẬT" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tien-ich/" title="Tin Tức - TIỆN ÍCH" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/ai/" title="Tin Tức - AI" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/khoa-hoc/" title="Tin Tức - KHOA HỌC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-chuyen-mon/" title="Tin Tức - HOẠT ĐỘNG CHUYÊN MÔN" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-cong-doan/" title="Tin Tức - CÔNG ĐOÀN" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-doan-the/" title="Tin Tức - ĐOÀN THỂ" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tuyen-sinh-huong-nghiep/" title="Tin Tức - TUYỂN SINH - HƯỚNG NGHIỆP" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tuyen-sinh-2025/" title="Tin Tức - TUYỂN SINH 2025" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/lich-cong-tac-tuan/" title="Tin Tức - Lịch công tác tuần" type="application/rss+xml">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/jquery/jquery.min.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/language/vi.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/global.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/news.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/main.js">
<link rel="preload" as="script" href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1816161148536198">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/bootstrap.min.js">
<link rel="StyleSheet" href="https://tinhocdct.xyz/assets/css/font-awesome.min.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/bootstrap.non-responsive.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/style.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/news.css">
<style>
	body{background: #fff;}
</style>
	</head>
	<body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG</h2>
		<p class="pull-right"><a title="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG" href="https://tinhocdct.xyz/">https://tinhocdct.xyz</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Sao Lưu và Khôi Phục Cơ Sở Dữ Liệu MySQL bằng Mysqldump</h1>
		<ul class="list-inline">
			<li>Chủ nhật - 14/12/2025 20:49</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			Trong hướng dẫn này, chúng ta sẽ tìm hiểu cách thực hiện sao lưu và khôi phục cơ sở dữ liệu MySQL hoặc MariaDB bằng công cụ dòng lệnh mysqldump.
		</div>
				<div class="imghome">
			<img alt="MySQL" src="https://tinhocdct.xyz/uploads/news/2025_12/mysql.png" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Tệp sao lưu được tạo bởi mysqldump thực chất là một lệnh MySQL có thể được sử dụng để khôi phục cơ sở dữ liệu gốc. Mysqldump cũng hỗ trợ tạo tệp sao lưu ở định dạng CSV và XML.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Bạn cũng có thể sử dụng mysqldump để di chuyển cơ sở dữ liệu MySQL của bạn từ một máy chủ sang máy chủ khác.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Nếu bạn không sao lưu cơ sở dữ liệu của mình, rủi ro mất dữ liệu do lỗi phần mềm hoặc lỗi ổ cứng có thể là một thảm họa không thể khôi phục được. Để tiết kiệm thời gian và đảm bảo an toàn dữ liệu, tôi khuyên bạn nên thực hiện sao lưu đều đặn cho cơ sở dữ liệu của mình.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-family: Inter, sans-serif; color: black; font-size: 20px; box-sizing: border-box; font-weight: bolder;">I. Cú Pháp của Mysqldump</span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Trước khi bắt đầu sử dụng mysqldump, hãy xem qua cú pháp cơ bản.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Cấu trúc của lệnh mysqldump như sau:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<div class="hcb_wrap" style="margin-bottom:26px; margin-top:26px; padding:0px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px">
<pre class="prism line-numbers language-bash" data-lang="Bash" style="border:none; padding:24.5px 21px 24.5px 47.9404px; width:760px; border-radius:3px; text-align:left">
<span style="font-size:14px"><span style="box-sizing:border-box"><span style="--hcb-clipbtn-opacity:0"><span style="display:block"><span style="position:relative"><span style="z-index:0"><span style="color:rgb(82, 82, 82);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="font-size:inherit"><span style="background:none 0% 0% / auto repeat scroll padding-box border-box rgb(45, 46, 41);"><span style="box-sizing:border-box"><span style="overflow:auto"><span style="display:block"><span style="font-family:Menlo, Consolas, &#039;Hiragino Kaku Gothic ProN&#039;, &#039;Hiragino Sans&#039;, Meiryo, sans-serif"><span style="letter-spacing:0.1px"><span style="line-height:1.5"><span style="position:static"><span style="overflow-wrap:normal"><span style="color:rgb(249, 249, 246);"><span style="hyphens:none"><span style="tab-size:4"><span style="text-shadow:none"><span style="white-space:pre"><span style="word-break:normal"><span style="word-spacing:normal"><span style="counter-reset:linenumber 0"><code class="language-bash" data-hcb-clip="1" style="box-sizing:border-box; background:none 0% 0% / auto repeat scroll padding-box border-box rgb(45, 46, 41); border:none; border-radius:4px; font-size:inherit; padding:0px; display:block; white-space:inherit; font-family:inherit; line-height:inherit; overflow-wrap:normal; color:rgb(249, 249, 246); hyphens:none; tab-size:4; text-align:left; text-shadow:none; word-break:normal; word-spacing:normal; position:relative">mysqldump <span class="token punctuation" style="font-size:inherit; padding:0px"><span style="box-sizing:border-box"><span style="color:rgb(248, 248, 242);"><span style="font-family:inherit"><span style="line-height:inherit">&#91;</span></span></span></span></span>option<span class="token punctuation" style="font-size:inherit; padding:0px"><span style="box-sizing:border-box"><span style="color:rgb(248, 248, 242);"><span style="font-family:inherit"><span style="line-height:inherit">&#93;</span></span></span></span></span> <span class="token operator" style="font-size:inherit; padding:0px"><span style="box-sizing:border-box"><span style="color:rgb(249, 38, 114);"><span style="font-family:inherit"><span style="line-height:inherit">&gt;</span></span></span></span></span> file.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
<span style="font-size:14px"><span style="box-sizing:border-box"><span style="--hcb-clipbtn-opacity:0"><span style="display:block"><span style="position:relative"><span style="z-index:0"><span style="color:rgb(82, 82, 82);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">option – các tùy chọn của mysqldump<br style="box-sizing:border-box" />
file.sql – tên tệp để lưu trữ sao lưu cơ sở dữ liệu</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Để sử dụng mysqldump, bạn phải có quyền truy cập vào máy chủ MySQL.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="II_Sao_Luu_Co_So_Du_Lieu_Don_Gian" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">II. Sao Lưu Cơ Sở Dữ Liệu Đơn Giản</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Trường hợp sử dụng phổ biến nhất của mysqldump là để sao lưu một cơ sở dữ liệu.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Ví dụ: để tạo một bản sao lưu của cơ sở dữ liệu có tên là “database_name”, sử dụng quyền của người dùng “root” và lưu vào tệp “database_name.sql”, hãy chạy lệnh sau:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysqldump -u root -p database_name &gt; database_name.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Bạn sẽ được yêu cầu nhập mật khẩu cho người dùng “root”. Sau khi xác minh mật khẩu thành công, quá trình sao lưu dữ liệu sẽ bắt đầu. Thời gian thực hiện phụ thuộc vào kích thước cơ sở dữ liệu và bạn cần đợi quá trình hoàn thành.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Nếu bạn đăng nhập với một người dùng khác, có quyền sao lưu mà không cần mật khẩu, bạn có thể bỏ qua các tùy chọn -u và -p:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysqldump database_name &gt; database_name.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="III_Sao_Luu_Nhieu_Co_So_Du_Lieu" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">III. Sao Lưu Nhiều Cơ Sở Dữ Liệu</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Để sao lưu nhiều cơ sở dữ liệu bằng một lệnh, sử dụng tùy chọn –database và theo sau là các tên cơ sở dữ liệu bạn muốn sao lưu. Mỗi tên cơ sở dữ liệu được phân tách bằng dấu cách.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysqldump -u root -p --databases database_name_a database_name_b &gt; databases_a_b.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Lệnh trên sẽ tạo một tệp sao lưu chứa cả cơ sở dữ liệu A và B.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="IV_Sao_Luu_Tat_Ca_Cac_Co_So_Du_Lieu_Trong_May_Chu" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">IV. Sao Lưu Tất Cả Các Cơ Sở Dữ Liệu Trong Máy Chủ</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Sử dụng tùy chọn –all-databases để sao lưu toàn bộ cơ sở dữ liệu của bạn.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysqldump -u root -p --all-databases &gt; all_databases.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Tương tự như ví dụ trước, lệnh này sẽ tạo ra một bản sao lưu duy nhất chứa tất cả các cơ sở dữ liệu trên máy chủ của bạn.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="V_Sao_Luu_Tat_Ca_Cac_Co_So_Du_Lieu_Vao_Nhieu_Tep" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">V. Sao Lưu Tất Cả Các Cơ Sở Dữ Liệu Vào Nhiều Tệp</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Mysqldump không hỗ trợ tùy chọn sao lưu tất cả các cơ sở dữ liệu vào nhiều tệp, nhưng bạn có thể thực hiện điều này dễ dàng bằng cách sử dụng vòng lặp FOR trong bash:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
for DB in $(mysql -e &#039;show databases&#039; -s --skip-column-names); do<br style="box-sizing:border-box" />
mysqldump $DB &gt; &quot;$DB.sql&quot;;<br style="box-sizing:border-box" />
done</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Lệnh trên sẽ tạo ra các tệp sao lưu khác nhau cho mỗi cơ sở dữ liệu.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="VI_Tao_Ban_Sao_Luu_Nen_voi_Thoi_Gian" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">VI. Tạo Bản Sao Lưu Nén với Thời Gian</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Nếu kích thước của cơ sở dữ liệu lớn, việc nén có thể là ý tưởng tốt để tạo ra một tệp sao lưu. Để thực hiện điều này, chỉ cần chuyển đầu ra thành tệp gzip:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysqldump database_name | gzip &gt; database_name.sql.gz</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="VII_Tao_Ban_Sao_Luu_voi_Dieu_Chinh_Thoi_Gian" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">VII. Tạo Bản Sao Lưu với Điều Chỉnh Thời Gian</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Nếu bạn muốn giữ nhiều bản sao lưu trong cùng một thư mục, bạn có thể thêm ngày hiện tại để phân biệt giữa các tệp sao lưu:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysqldump database_name &gt; database_name-$(date +%Y%m%d).sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Lệnh trên sẽ tạo ra một tệp có định dạng như sau: “database_name-20180617.sql”</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="VIII_Khoi_Phuc_Co_So_Du_Lieu_Da_Sao_Luu" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">VIII. Khôi Phục Cơ Sở Dữ Liệu Đã Sao Lưu</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Bạn có thể khôi phục cơ sở dữ liệu bằng cách sử dụng mysql. Cú pháp như sau:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysql -u root -p -e &quot;create database database_name&quot;;<br style="box-sizing:border-box" />
mysql -u root -p database_name &lt; database_name.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Trong hầu hết các trường hợp, bạn sẽ cần phải tạo ra cơ sở dữ liệu trước, nếu chưa tồn tại.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Trong ví dụ dưới đây, lệnh đầu tiên sẽ tạo ra một cơ sở dữ liệu có tên là “database_name” và sau đó sẽ nhập tệp sao lưu “database_name.sql” vào nó:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysql -u root -p -e &quot;create database database_name&quot;;<br style="box-sizing:border-box" />
mysql -u root -p database_name &lt; database_name.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="IX_Khoi_Phuc_Mot_Co_So_Du_Lieu_tu_Tep_Sao_Luu_Tat_Ca_Cac_Co_So_Du_Lieu" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">IX. Khôi Phục Một Cơ Sở Dữ Liệu từ Tệp Sao Lưu Tất Cả Các Cơ Sở Dữ Liệu</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Nếu bạn đã sao lưu tất cả cơ sở dữ liệu của mình bằng tùy chọn –all-databases và bạn muốn khôi phục một cơ sở dữ liệu duy nhất từ tệp sao lưu, bạn có thể sử dụng tùy chọn –one-database như dưới đây:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysql --one-database database_name &lt; all_databases.sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="X_Xuat_hoac_Nhap_Co_So_Du_Lieu_bang_Mot_Dong_Lenh" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">X. Xuất hoặc Nhập Cơ Sở Dữ Liệu bằng Một Dòng Lệnh</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Thay vì tạo ra một tệp sao lưu và sau đó nhập tệp đó vào một cơ sở dữ liệu khác, bạn có thể sử dụng cách sau để làm nhanh chóng:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mysqldump -u root -p database_name | mysql -h remote_host -u root -p remote_database_name</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Lệnh trên sẽ chuyển đầu ra đến máy chủ MySQL client ở remote_host và nhập vào cơ sở dữ liệu có tên là remote_database_name. Trước khi chạy lệnh, đảm bảo rằng cơ sở dữ liệu đã tồn tại trên máy chủ remote.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h2 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:20px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="line-height:1.3"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="XI_Tu_Dong_Sao_Luu_voi_Cong_Viec_Cron" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone"><strong style="box-sizing:border-box; font-weight:bolder">XI. Tự Động Sao Lưu với Công Việc Cron</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h2>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Tự động hóa sao lưu cơ sở dữ liệu đơn giản như một công việc định kỳ, lệnh mysqldump sẽ chạy vào thời gian bạn chỉ định.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Để cài đặt sao lưu tự động cơ sở dữ liệu bằng cronjob, làm theo các bước sau:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h3 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:19px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="1_Tao_mot_tep_mycnf_tai_duong_dan_home" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone">1. Tạo một tệp .my.cnf tại đường dẫn home:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
sudo nano ~/.my.cnf</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h3 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:19px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="2_Sao_chep_va_dan_doan_ma_sau_vao_do" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone">2. Sao chép và dán đoạn mã sau vào đó:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
&#91;client&#93; user = dbuser<br style="box-sizing:border-box" />
password = dbpasswd</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Hãy nhớ thay thế “dbuser” và “dbpasswd” bằng tên người dùng và mật khẩu của máy chủ MySQL.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h3 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:19px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="3_Han_che_quyen_truy_cap_cho_tep_thong_tin_chi_cho_nguoi_dung_ban_muon_co_quyen_truy_cap" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone">3. Hạn chế quyền truy cập cho tệp thông tin chỉ cho người dùng bạn muốn có quyền truy cập:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
chmod 600 ~/.my.cnf</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h3 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:19px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="4_Tao_mot_thu_muc_de_luu_tru_cac_tep_sao_luu" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone">4. Tạo một thư mục để lưu trữ các tệp sao lưu:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
mkdir ~/db_backups</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h3 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:19px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="5_Mo_tep_crontab" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone">5. Mở tệp crontab:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
crontab -e</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
&nbsp;
<h3 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:19px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="6_Them_lenh_nhu_vi_du_sau_de_cronjob_chay_sao_luu_co_so_du_lieu_vao_3_gio_sang_moi_ngay" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone">6. Thêm lệnh như ví dụ sau để cronjob chạy sao lưu cơ sở dữ liệu vào 3 giờ sáng mỗi ngày:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
0 3 * * * /usr/bin/mysqldump -u dbuser mydb &gt; /home/username/db_backups/mydb-$(date +%Y%m%d).sql</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Hãy đảm bảo thay thế “username” bằng tên người dùng thực tế.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<h3 style="width:760px; max-width:768px; text-align:justify; text-indent:0px; -webkit-text-stroke-width:0px; margin-bottom:13px"><span style="font-size:19px"><span style="box-sizing:border-box"><span style="color:black"><span style="text-rendering:optimizespeed"><span style="font-family:Inter, sans-serif"><span style="font-weight:700"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span id="7_Ban_cung_co_the_tao_mot_tep_cronjob_de_xoa_cac_ban_sao_luu_cu_hon_30_ngay" style="box-sizing:border-box"><span style="-webkit-box-decoration-break:clone"><span style="box-decoration-break:clone">7. Bạn cũng có thể tạo một tệp cronjob để xóa các bản sao lưu cũ hơn 30 ngày:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><code style="box-sizing:border-box; background:rgb(241, 241, 241); border:1px solid rgb(225, 225, 225); border-radius:4px; font-size:0.9em; padding:0.2rem 0.5rem; margin-right:2px; margin-left:2px">bash<br style="box-sizing:border-box" />
find /đường/dẫn/tới/sao_lưu -type f -name &quot;*.sql&quot; -mtime +30 -delete</code></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(5, 5, 5);"><span style="font-family:Inter, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="background-color:rgb(255, 255, 255);"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Tất nhiên, bạn cần sửa đường dẫn và tên tệp.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
&nbsp;
		</div>
				<div id="author">
						<p>
				<strong>Tác giả bài viết:</strong>
				Thanh Sơn
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://tinhocdct.xyz/tin-cong-nghe/sao-luu-va-khoi-phuc-co-so-du-lieu-mysql-bang-mysqldump-547.html" title="Sao Lưu và Khôi Phục Cơ Sở Dữ Liệu MySQL bằng Mysqldump">https://tinhocdct.xyz/tin-cong-nghe/sao-luu-va-khoi-phuc-co-so-du-lieu-mysql-bang-mysqldump-547.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG
		</div>
		<div id="contact">
			<a href="mailto:webmaster@tinhocdct.xyz">webmaster@tinhocdct.xyz</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://tinhocdct.xyz/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
<script src="https://tinhocdct.xyz/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_is_recaptcha=0;</script>
<script src="https://tinhocdct.xyz/assets/js/language/vi.js"></script>
<script src="https://tinhocdct.xyz/assets/js/global.js"></script>
<script src="https://tinhocdct.xyz/themes/default/js/news.js"></script>
<script src="https://tinhocdct.xyz/themes/default/js/main.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1816161148536198"
     crossorigin="anonymous"></script>
<script src="https://tinhocdct.xyz/themes/default/js/bootstrap.min.js"></script>
</body>
</html>