MYSQL逻辑备份

首先用mysqldump进行完全备份

[root@logan ~]# mysqldump -uroot -p123 --all-databases > /all.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.

停掉mysql服务

[root@logan]# killall mysqld
mysqld: no process found

手动建立/usr/local/mysql/data 目录

[root@logan mysql]# chown -R mysql.mysql data/
[root@logan mysql]# ll -d data/
drwxr-xr-x 2 mysql mysql 6 7月   3 16:28 data/

初始化mysql

复制代码
[root@logan]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
2019-07-03T08:17:14.051524Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-03T08:17:14.537987Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-07-03T08:17:14.654008Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-07-03T08:17:14.712419Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f6f91572-9d6a-11e9-94ea-000c29d7f62f.
2019-07-03T08:17:14.713328Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-07-03T08:17:14.713951Z 1 [Note] A temporary password is generated for root@localhost: Fp6rfD?e,quk     #这是初始密码
复制代码

重启服务,登录

复制代码
[root@logan]# systemctl restart mysqldd
[root@logan]# mysql -uroot -pFp6rfD?e,quk
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
复制代码

修改数据库密码

mysql> set password=password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

查看当前数据库

复制代码
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
复制代码

恢复备份

[root@logan mysql]# mysql -uroot -p123 < /all.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

重新登录进行查看

复制代码
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| file               |
| file1              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

转载于:https://www.cnblogs.com/MR-ws/p/11127855.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值