简体   繁体   中英

Restore MySQL database from .mysql file

I have a backup.mysql file that I created using mysqldump .

How can I use that to restore the database? I opened the file in Sublime Text, and here is what its beginning looks like!

文件内容

The dump you produced is a SQL script you can run with any tool you want. As OP from this question How do I restore a dump file from mysqldump? , if you try to restore it with MySQL Administrator or other software providing specific backup/restore functions, it can throw an error because it asks for a particular format (his own format); but if the dump has been produced correctly, you can run it with any MySQL client, for example with the command line tool :

mysql -h hostname -u username -p yourschema < ./path/to/the/script.mysql
  1. Copy your backup.sql file to the working directory: C:\\xampp\\mysql\\bin . (or whatever your path)

  2. In your command prompt or terminal switch to the MySQL directory. cd c:\\xampp\\mysql\\bin (or whatever your path)

  3. Open the MySQL Database system mysql –h localhost –u root (or whatever your credentials)
  4. You need to re-grant permissions: GRANT ALL ON your_db_here.* to 'root'@'localhost'; (or whatever your credentials)

  5. You need to re-create the database: CREATE DATABASE your_db_here;

  6. Start using the database: USE your_db_here;
  7. Import the dump file that you created: source backup.mysql
  8. Using DESCRIBE commands and "SELECT * FROM" commands ensure that your database has been restored properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM