To Export a database, open up terminal, making sure that you are not logged into MySQL and type,
mysqldump -u [username] -p [database name] > [database name].sql
The database that you selected in the command will now be exported to your droplet.
To import a database, first create a new blank database in the MySQL shell to serve as a destination for your data.
CREATE DATABASE newdatabase;
Then log out of the MySQL shell and type the following on the command line:
mysql -u [username] -p newdatabase < [database name].sql
With that, your chosen database has been imported into your destination database in MySQL.
When you first install MySQL, you have to set up your root password. However, should you forget it at any point, you can still recover it.
In terminal, stop the MySQL process
In safe mode, you will be able to make changes within the MySQL system with a root password alone, without the need for MySQL root password.
sudo mysqld_safe --skip-grant-tables &
Once safe mode has started up, log into MySQL and when prompted, use your standard root password.
mysql -u root mysql
Finally, set up the new MySQL root password by typing the command below. Replace "newpassword" with the password of your choice.
update user set password=PASSWORD("newpassword") where User='root';
Be sure to reload everything:
and you now have a new root password.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.