Ubantu下如何安裝mysql資料庫,以及如何備份sql檔案和運行sql檔案!,ubantumysql

來源:互聯網
上載者:User

Ubantu下如何安裝mysql資料庫,以及如何備份sql檔案和運行sql檔案!,ubantumysql
ubuntu上安裝mysql其實比起window下面安裝還簡單,就下面幾條命令,中間只需輸入一次密碼,其他的操作都有系統自動完成。  1. sudo apt-get install mysql-server   2. apt-get isntall mysql-client
   3.  sudo apt-get install libmysqlclient-dev

安裝好mysql之後,檢查是否安裝成功:sudo netstat -tap | grep mysql

檢查成功後,那就是做做簡單的測試了
mysql -u root -p

其他的操作命令就和平時的一樣了。

下面主要講講如何匯出資料庫檔案和匯入資料庫檔案:

一、匯出資料庫用mysqldump命令(注意mysql的安裝路徑,即此命令的路徑):
1、匯出資料和表結構:
mysqldump -u使用者名稱 -p密碼 資料庫名 > 資料庫名.sql
$/usr/  mysqldump -uroot -p abc > abc.sql
敲斷行符號後會提示輸入密碼


2、只匯出表結構
mysqldump -u使用者名稱 -p密碼 -d 資料庫名 > 資料庫名.sql
$/usr/  mysqldump -uroot -p -d abc > abc.sql

註:/usr/  --->  mysql的data目錄


二、匯入資料庫
1、首先建空資料庫
mysql>create database abc;

2、匯入資料庫
方法一:
(1)選擇資料庫
mysql>use abc;
(2)設定資料庫編碼
mysql>set names utf8;
(3)匯入資料(注意sql檔案的路徑)
mysql>source /home/abc/abc.sql;
方法二:
mysql -u使用者名稱 -p密碼 資料庫名 < 資料庫名.sql
#mysql -uabc_f -p abc < abc.sql





相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.