mysqldump备份数据
2024-10-08 22:56:29
create database test;
use test;
create table test(id int,name char(8));
insert into test values(1,'peter');
mysql服务bin目下执行:
1. 备份数据
mysqldump --opt -uroot -p123456 test > test.dump
2. 从备份文件恢复数据,需要先建立好数据库test
mysql -uroot -p123456 test < test.dump
3. 只备份表结构
mysqldump --no-data -uroot -p123456 test > test-nodata.dump
4. 备份多个数据库
mysqldump --opt -uroot -p123456 --databases test test2 test3> test.dump
导入多个库数据
mysql -uroot -p123456 < test.dump
5. 跨机器备份数据,源端mysql服务器src_host_ip,目标端mysql服务器dsc_host_ip
目标mysql端建立提供远程访问的用户,并赋予数据库权限
create database test
create user root@'src_host_ip' identified by '123456';
grant all privileges on *.* to root@'src_host_ip' identified by '123456';
源端mysql拷贝数据
mysqldump --opt -uroot -p123456 test |mysql -uroot -p123456 -hdsc_host_ip test
6. 与mysqlimport结合使用,备份大表
执行备份之前,先在两台host上执行如下命令:
mysql> show variables like '%secure_file%';
+------------------+----------+
| Variable_name | Value |
+------------------+----------+
| secure_file_priv | e:\test\ |
+------------------+----------+
1 row in set, 1 warning (0.00 sec)
如果secure_file_priv值为NULL,在mysql服务器配置文件my.ini中增加一项,并重启服务器
secure-file-priv=e:/test
源服务器上执行以下命令,备份test2数据库,并将e:/test文件夹备份到目标服务器上同一目录
mysqldump -uroot -p123456 --tab=e:/test test2
目标服务器上,执行以下命令:
>type e:\\test\\test2.sql | mysql -uroot -p123456 test2
mysql: [Warning] Using a password on the command line interface can be insecure. >mysqlimport -uroot -p123456 test2 e:/test/test2.txt
mysqlimport: [Warning] Using a password on the command line interface can be ins
ecure.
test2.test2: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0 >mysqladmin -uroot -p123456 flush-privileges
注意:mysqlimport中涉及到的e:/test/test2.txt路径前缀e:/test/一定要写,与secure-file-priv一致
type命令类似Linux中的cat,后面的路径得用windows中的\\
最新文章
- Android课程---关于Service的学习(后台运行)
- WebAPI生成可导入到PostMan的数据
- 封装pyMysql
- Trie树(c++实现)
- jQuery hide()并不等于hide(0)
- 5 Tips for creating good code every day; or how to become a good software developer
- 。。。HibernateTemplate与Session。。。
- mybatis-generator 代码自动生成工具
- HDU 2084 数塔(动态规划)
- GIT Learning
- FindStringExact
- 删除CentOS / RHEL的库和配置文件(Repositories and configuraiton files)
- mmap学习
- Eight
- Ext3和Ext4文件系统区别
- form表单action=";";的作用
- linux开机启动流程及需要开机启动服务讲解和修改及防火墙
- Linux系统的RAID磁盘阵列
- Ansible剧本介绍及使用演示(week5_day2)--技术流ken
- MFC入门(一)-- 第一个简单的windows图形化界面小程序(打开计算器,记事本,查IP)