Linux下MySQL的备份与还原
2.1 备份
[root@localhost ~]# cd /var/lib/mysql (进入到MySQL库目录,根据自己的MySQL的安装情况调整目录)
[root@localhost mysql]# mysqldump -u root -p voice>voice.sql,输入密码即可。
2.2 还原
法一:
[root@localhost ~]# mysql -u root -p 回车,输入密码,进入MySQL的控制台"mysql>",同1.2还原。
法二:
[root@localhost ~]# cd /var/lib/mysql (进入到MySQL库目录,根据自己的MySQL的安装情况调整目录)
[root@localhost mysql]# mysql -u root -p voice<voice.sql,输入密码即可。
如果备份出现下列错误:
[root@ba ~]# mysqldump --default-character-set=utf8 --databases susite ucme >/home/2db-uch-ss-20120312.sql
mysqldump: Got error: 1449: The user specified as a definer ('mbuch'@'10.6.21.%') does not exist when using LOCK TABLES
建用户
mysql> grant select,insert,update,delete on mchome.* to 'mbuch'@'10.6.21.%' identified by 'mbuch';
Query OK, 0 rows affected (0.82 sec)
mysql> flush privileges;
如果报错:
Enter password: ERROR at line 1304: Unknown command '\'.
mysql -u root -p voice<all.sql --default-character-set=utf8
mysql -u root -p <all.sql --default-character-set=gbk