Use SQL statements to back up and restore database _ MySQL
Source: Internet
Author: User
Use SQL statements to back up and restore the database bitsCN. comeg:
/*
Back up a database using SQL statements
*/
Backup database mydb
To disk = 'C:/DBBACK/mydb. bak'
-- Specify the path and file name of the database to be backed up. note: The path folder must have been created. the file name can be identified by date.
/*
Restore a database using SQL statements
*/
USE master
Restore database mydb
From disk = 'C:/DBBACK/mydb. bak'
WITH REPLACE
Note: In many cases, the data cannot be restored directly because it is not exclusively opened. the following process may be used.
-- Kill the connection to a database
Create proc KillSpid (@ DBName varchar)
AS
BEGIN
DECLARE @ SQL varchar
DECLARE @ SPID int
SET @ SQL = 'Clare CurrentID CURSOR
SELECT spid FROM sysprocesses WHERE dbid = db_id (''' + @ DBName + ''')'
Fetch next from CurrentID INTO @ SPID
WHILE @ FETCH_STATUS <>-1
BEGIN
Exec ('Kill '+ @ SPID)
Fetch next from CurrentID INTO @ SPID
END
CLOSE CurrentID
DEALLOCATE CurrentID
END
It is best to use a single user to operate the database after kill the user
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.