How To Import and Export Databases and Reset a Root Password in MySQL
How To Import and Export Databases and Reset a Root Password in MySQL
If you are working with MySQL databases, it's important to know how to import and export them, as well as how to reset a root password if necessary. This tutorial will walk you through these important tasks.
Exporting a Database
- Open up your MySQL command line interface
- Type the following command:
mysqldump -u username -p database_name > backup.sql - Enter your MySQL password when prompted
- A new file called "backup.sql" will be created in the directory where you ran the command. This file contains all of the data in your database.
Importing a Database
- Open up your MySQL command line interface
- Type the following command:
mysql -u username -p database_name < backup.sql - Enter your MySQL password when prompted
- Your database will now be imported from the backup file
Resetting a Root Password
- Stop the MySQL service
- Open up your MySQL configuration file (usually located at /etc/mysql/my.cnf)
- Add the following line under the [mysqld] section:
skip-grant-tables - Restart the MySQL service
- Open up your MySQL command line interface
- Type the following command:
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root'; - Type the following command:
FLUSH PRIVILEGES; - Remove the
skip-grant-tablesline from your MySQL configuration file - Restart the MySQL service
- You can now log in as root using your new password
Комментарии
Отправить комментарий