mysql数据备份并重置

mysql数据备份并重置

1.备份mysql数据

mysqldump -uroot --single-transaction -R -E --databases lc2 cpm a10_goods self_warehouse > /mnt/vdc1/var/lib/mysql/datadir/lc2_cpm_a10_goods_self_warehouse.sql -p Y6B2wb

2.初始化mysql

mysqld --initialize;

3.修改配置文件

z mysql
cd /etc/mysql/mysql.conf.d
vim mysql.cnf

配置文件如下:

[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
#datadir		= /mnt/vdc1/var/lib/mysql/data # 旧数据
datadir		= /mnt/vdc1/var/lib/mysql/my_data # 新数据
log-error	= /var/log/mysql/error.log
# By default we only accept connections from localhost
bind-address	= 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# binlog
#server_id=2
#log-bin=/var/log/mysql/mysql-bin
#expire_logs_days = 3
#binlog_format = ROW
#binlog_do_db = cpm
#binlog_do_db = lc2
# has gone away
max_allowed_packet=100M
wait_timeout=28800

4.分配数据可执行权限

chown mysql:mysql /mnt/vdc1/var/lib/mysql/my_data -R

5.查找mysql重置后的root密码

grep -a generated /var/log/mysql/error.log

6.登录数据库,修改密码

mysql -uroot -p

mysql>
alter user ‘root’@‘localhost’ identified by ‘Y6B2wb’;
flush privileges;

7.创建备份还原的数据库

mysql>
create database mydatabase character set utf8mb4 collate utf8mb4_unicode_ci;
create database cpm character set utf8mb4 collate utf8mb4_unicode_ci;
create database a10_goods character set utf8mb4 collate utf8mb4_unicode_ci;
create database lc2 character set utf8mb4 collate utf8mb4_unicode_ci;
create database self_warehouse character set utf8mb4 collate utf8mb4_unicode_ci;

8.重新给账号分配权限

mysql>
grant select,insert,update,delete on self_warehouse.* to [email protected] identified by ‘U2Fx1’;
grant select,insert,update,delete on self_warehouse.* to [email protected] identified by ‘U2Fx1’;
grant select,insert,update,delete on lc2.* to [email protected] identified by ‘U2Fx1’;
grant select,insert,update,delete on lc2.* to [email protected] identified by ‘U2Fx1’;
grant select,insert,update,delete on cpm.* to [email protected] identified by ‘U2Fx1’;
grant select,insert,update,delete on cpm.* to [email protected] identified by ‘U2Fx1’;
grant select,insert,update,delete on a10_goods.* to [email protected] identified by ‘U2Fx1’;
grant select,insert,update,delete on a10_goods.* to [email protected] identified by ‘U2Fx1’;
flush privileges;

9.还原数据

pv /mnt/vdc1/var/lib/mysql/datadir/lc2_cpm_a10_goods_self_warehouse.sql | mysql -uroot --ssl-mode=disabled -p

你可能感兴趣的:(关系数据库(mysql,数据库,linux,mysql,adb,android)