Home > Database > Mysql Tutorial > MySQL数据库及表的备份与还原_MySQL

MySQL数据库及表的备份与还原_MySQL

WBOY
Release: 2016-05-30 17:11:25
Original
1356 people have browsed it

备份

导出数据库所有表结构

mysqldump -uroot -ppassword -d dbname > db.sql
Copy after login

导出数据库某个表结构

mysqldump -uroot -ppassword -d dbname tablename > db.sql
Copy after login

导出数据库所有表结构及数据

mysqldump -uroot -ppassword dbname > db.sql
Copy after login

导出数据库某个表结构及数据

mysqldump -uroot -ppassword dbname tablename > db.sql
Copy after login

导出部分数据

--where="条件"
mysqldump -uroot -ppassword dbname tablename -w "条件" > db.sql
Copy after login

-w或–where,条件一定要用双引号包围,单引号不行。

注意
导出数据不需要-d


可能会出现如下错误

mysqldump: Got error 1044: Access denied for use ‘zndw’@’localhost’ to database ‘scilibrary’ when doing LOCK TABLES

出现这个错误的原因是该用户无lock tables权限。

解决办法
(1) 给该用户赋予lock tables权限
(2) 加上--skip-lock-tables,如

mysqldump -uroot -ppassword dbname --skip-lock-tables > db.sql
Copy after login

导入

source xxx.sql
Copy after login

(1) 语句后面不能有分号;
(2) 用户要有insert等权限

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template