mysql数据库的备份与恢复

mysql数据库的备份与恢复

mysqldump命令用于备份数据库数据

格式为:mysqldump 【参数】【数据库名称】

                                                   

如果是用mysqldump 来做备份、那么备份用户的相关权限如下:

create user dumper@'127.0.0.1' identified by '123456';

grant select on loltop.* to dumper@'127.0.0.1';

grant lock tables on loltop.* to dumper@'127.0.0.1';

grant show view on loltop.* to dumper@'127.0.0.1';

1.创建一个用于备份的用户‘dumper’  % 表示可以远程备份。

MariaDB [(none)]> create user dumper@'%' identified by '123456';         

Query OK, 0 rows affected (0.00 sec)

2.为dumper用户增加loltop库的select权限。

MariaDB [(none)]> grant select on loltop.* to dumper@'%';        

Query OK, 0 rows affected (0.00 sec)

3. 给dumper用户一个lock tables 权限

MariaDB [(none)]> grant lock tables on loltop.* to dumper@'%';        

Query OK, 0 rows affected (0.00 sec)

4.为dumper用户加上show view 权限

MariaDB [(none)]> grant show view on loltop.* to dumper@'%';        

Query OK, 0 rows affected (0.00 sec)

5.dumper用户本地备份

mysqldump -h127.0.0.1 -udumper -p123456 --databases loltop

6.dumper用户远程备份

mysqldump -h 192.168.1.160 -u dumper -p'123456' loltop > /root/dbname.dump

7. 远程导入mysql -h 192.168.1.160 -P 3306 -u dumper -p loltop</root/loltop.sql

8.一般用mysqldump 来备份数据,然后使用这么两个参数

--max_allowed_packet=1048576 --net_buffer_length=16384

需要在my.cnf 中配置   max_allowed_packet = 48M

数据的导入速度可以提升数以千倍

 

 

posted @ 2020-03-18 15:21  昌北F4  阅读(314)  评论(0编辑  收藏  举报