Home » Categories » Multiple Categories

How To Import and Export Databases and Reset a Root Password in MySQL

How to Import and Export Databases

Export

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 server instance.

Import

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.

How to Reset a Root Password

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.

Step One—Shut Down MySQL

In terminal, stop the MySQL process
 /etc/init.d/mysql stop

Step Two—Access MySQL Safe Mode

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

Step Three—Set Up a New Password

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:
 FLUSH PRIVILEGES;
and you now have a new root password.
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
How To Configure and Maintain Ghost from the Command Line
Viewed 6892 times since Sun, Dec 29, 2013
How To Set Up Apache Virtual Hosts on Ubuntu 12.04 LTS
Viewed 3801 times since Mon, Dec 23, 2013
How To Configure Varnish for Drupal with Apache on Debian and Ubuntu
Viewed 7552 times since Thu, Jan 2, 2014
How To Use a Simple Bash Script To Restart Server Programs
Viewed 3502 times since Fri, Dec 27, 2013
How To Use Dokku Plugins to Access Additional Functionality
Viewed 4924 times since Sun, Dec 29, 2013
How To Launch Your Site on a New Ubuntu 12.04 Server with LAMP, SFTP, and DNS
Viewed 2940 times since Thu, Dec 26, 2013
How To Use Traceroute and MTR to Diagnose Network Issues
Viewed 6993 times since Fri, Dec 27, 2013
How To Install And Run A Node.js App On Centos 6.4 64bit
Viewed 10700 times since Sun, Dec 29, 2013
How To Install Z Shell (zsh) on a Cloud Server
Viewed 2974 times since Fri, Dec 27, 2013
How To Copy Files With Rsync Over SSH
Viewed 6787 times since Fri, Dec 27, 2013