Mysql 逻辑备份>>>>完全备份恢复

首先用mysqldump进行完全备份

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

停掉mysql服务

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

手动建立/usr/local/mysql/data mulu

[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 my_autofs]# /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 my_autofs]# 

重启服务,登录

[root@logan my_autofs]# systemctl restart mysqldd
[root@logan my_autofs]# 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 < /my_autofs/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)

原来的数据回来了

猜你喜欢

转载自www.cnblogs.com/loganSxb/p/11127589.html