入門MySQL資料庫導入與導出及重置root密碼

如何導入和導出數據庫

要導出數據庫,打開終端,確保您未登錄MySQL並鍵入,

mysqldump -u [username] -p [database name] > [database name].sql 

您在命令中選擇的數據庫現在將導出到您的Droplet。

要導入數據庫,首先在MySQL shell中創建一個新的空白數據庫作為數據的目標。

CREATE DATABASE newdatabase; 

然後註銷MySQL shell,並在命令行中鍵入以下命令:

mysql -u [username] -p newdatabase With that, your chosen database has been imported into your destination database in MySQL. How to Reset a Root PasswordWhen 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 MySQLIn terminal, stop the MySQL process /etc/init.d/mysql stopStep Two—Access MySQL Safe ModeIn 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 mysqlStep Three—Set Up a New PasswordFinally, 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.By Etel Sverdlov

這樣,您選擇的數據庫已導入到MySQL中的目標數據庫。

如何重置root密碼

當您首次安裝MySQL時,您必須設置root密碼。但是,如果你忘記它在任何時候,你仍然可以恢復它。

第一步 - 關閉MySQL

在終端中,停止MySQL進程

 /etc/init.d/mysql stop

第二步 - 訪問MySQL安全模式

在安全模式下,您將能夠在MySQL系統中單獨使用root密碼進行更改,而無需MySQL root密碼。

sudo mysqld_safe --skip-grant-tables & 

一旦安全模式啟動,登錄MySQL並提示,使用您的標準root密碼。

mysql -u root mysql

第三步 - 設置新密碼

最後,通過鍵入以下命令設置新的MySQL root密碼。將“newpassword”替換為您選擇的密碼。

update user set password=PASSWORD("newpassword") where User='root';

一定要重新加載一切:

 FLUSH PRIVILEGES; 

並且您現在有一個新的root密碼。


分享到:


相關文章: