How to rollback on file import in mysql?

by ryan.murray , in category: MySQL , 3 months ago

How to rollback on file import in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by filiberto , 3 months ago


To rollback on a file import in MySQL, you need to follow these steps:

  1. Open the MySQL Command Line Client or any other MySQL client software.
  2. Connect to your MySQL server using the following command: mysql -u your_username -p Replace your_username with your MySQL username. You will be prompted to enter your MySQL password.
  3. Select the database where you imported the file: USE your_database; Replace your_database with the name of your database.
  4. Disable autocommit for the session to ensure that changes are not committed automatically: SET autocommit=0;
  5. Import your file using the source command: source /path/to/your/file.sql; Replace /path/to/your/file.sql with the actual path to your SQL file.
  6. If you want to rollback the import, use the following command: ROLLBACK; This will undo the changes made by the import process.
  7. After rolling back, you can enable autocommit again by executing the following command: SET autocommit=1;
  8. Finally, you can exit the MySQL client by typing: exit;

That's it! You have rolled back the file import in MySQL.