docker的mysql数据丢失,被黑客攻击
1、第一步进入docker的容器中。
docker exec -it mysql mysql -uroot -p123456
2、进入mysql查看权限
markdown
use mysql;
select host,user,authentication_string from mysql.user;
3、查看binlog
mysql> SHOW VARIABLES LIKE 'log_bin%';
+---------------------------------+-----------------------------+
| Variable_name | Value |
+---------------------------------+-----------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/binlog |
| log_bin_index | /var/lib/mysql/binlog.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
+---------------------------------+-----------------------------+
4、查询是否有binlog日志
[root@VM-12-13-opencloudos ~]# cd /home/mysql/data
[root@VM-12-13-opencloudos data]# ls
auto.cnf binlog.000003 binlog.000007 ca.pem '#ib_16384_1.dblwr' ib_logfile1 mysql.ibd server-cert.pem undo_002
bb92e54a9f51.err binlog.000004 binlog.000008 client-cert.pem ib_buffer_pool ibtmp1 performance_schema server-key.pem
binlog.000001 binlog.000005 binlog.index client-key.pem ibdata1 '#innodb_temp' private_key.pem sys
binlog.000002 binlog.000006 ca-key.pem '#ib_16384_0.dblwr' ib_logfile0 mysql public_key.pem undo_00
5、使用binlog恢复
mysqlbinlog --start-position=起始位置 --stop-position=结束位置 binlog.000007 | mysql -u 用户名 -p
先备份当前而
mysqldump -uroot -p T > /path/xxx.sql; # 备份数据库
show master status; # 查看当前的position位置,此时值为154
7.通过mysqlbinlog命令从binlog日志中导出可执行的SQL文件,并将数据导入到mysql
docker exec -it mysql bash
cd var/lib/mysql
mysqlbinlog /var/lib/mysql/binlog.000007 | mysql -uroot -p 123456
提示失败
ERROR: Binlog has bad magic number; It's not a binary log file that can be used by this version
8、还是修改密码吧
markdown
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456!';
flush privileges;
docker exec -it mysql mysql -uroot -p123456
use mysql;
select host,user,authentication_string from mysql.user;
发现远程登录 需要个新密码了。