入門MySQL數據庫導入與導出及重置root密碼
發布時間: 2018-07-15
要導出數據庫,打開終端,確保您未登錄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 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. By Etel Sverdlov
這樣,您選擇的數據庫已導入到MySQL中的目標數據庫。
當您首次安裝MySQL時,您必須設置root密碼。但是,如果你忘記它在任何時候,你仍然可以恢復它。
在終端中,停止MySQL進程
/etc/init.d/mysql stop
在安全模式下,您將能夠在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密碼。
上一篇: 騰科暑假班火熱進行中
下一篇: MySQL 文檔存儲介紹