数据库备份语句讲解
推荐一个讲解MySQL备份的博客链接:https://www.cnblogs.com/stache/p/5836261.html
数据库的备份
mysqldump -h127.0.0.1 -uroot –pabc -R "scopus_test" > /work/scopus_test0312.sql
参数讲解:
-h: 主机 eg: -h127.0.0.1 -h47.101.54.154
-u: 用户名 eg:-uroot -utest
-p: 密码 一般不进行输入,在语句数据完会出现输入的密文防止密码泄露
-R: 数据库中所有的 存储过程,表,视图等
"scopus_test" 为要备份的数据库名称
> 导出
/work/scopus_test0312.sql 保存的位置
默认的端口号为3306,可以使用 -P 进行指定端口
eg:
mysqldump -h127.0.0.1 -uroot –pabc -P33306 -R "scopus_test" > /work/scopus_test0312.sql
数据库还原
mysql -h127.0.0.1 –uroot –p scopus_test0312 </work/scopus_test0312.sql
参数讲解:
scopus_test0312 为要还原的数据库名称
< 还原导入
#为了防止乱码,可以使用--default-character-set=utf8 来进行指定编码
eg:
mysql -h127.0.0.1 -uroot -p --default-character-set=utf8 "qyjc_20180806_28"<d:/qyjc_sy.sql
备份表
mysqldump -uroot -p scopus_batch2 xml_docmeta > d:\xml_docmeta.sql
参数讲解:
scopus_batch2 为数据库
xml_docmeta 为要进行备份的表
#如果只想备份表结构可以使用 -d
eg:
mysqldump -h127.0.0.1 -uroot -p -d "qyjc_20180806"
cma_jl_lab_instrument_device_ext
cma_jl_lab_cert
cma_jl_lab_qualification_item_ext
agl_browse_log agl_log_config
agl_system_log agl_trace_log
agl_ip_access_log
qy_message qy_order_log
qy_user_log_browse
qy_information_bak
qy_sms_mail
qy_user_habit > d:/qyjc_20180806.sql
还原表与还原数据库相同
mysql -h127.0.0.1 –uroot –p --default-character-set=utf8 qyjc_20180806 <d:/qyjc_20180806.sql
权限问题,授权 给 root 所有sql 权限
mysql> grant all privileges on *.* to root@"%" identified by "passwd";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)