ubuntu12.04 安裝和卸載mysql

來源:互聯網
上載者:User

標籤:details   move   bin   csdn   base   word   html   boa   清理   

轉: http://blog.csdn.net/skylinethj/article/details/38524629   ubuntu12.04 安裝和卸載mysql

 

關於授權的文章請看 http://blog.csdn.net/id19870510/article/details/8434421

===================================================================

1:登入系統,安裝之前最好先,

[html] view plaincopy  
  1. apt-get update  

否則會出現找不到安裝檔案得錯誤提示

 

2:安裝MySQL伺服器以及用戶端

 

[html] view plaincopy  
  1. apt-get install mysql-server mysql-client    

安裝得過程中會提示你輸入root得密碼。

 

3:安裝完成以後預設mysql不能遠端存取

 

[html] view plaincopy  
  1. vi /etc/mysql/my.cnf  
[html] view plaincopy  
  1.   注釋掉 bind-address = 127.0.0.1  


4:用root登入到mysql,然後用grant命令添加使用者,如:

 

 

[html] view plaincopy  
  1. mysql> grant all privileges on 需要訪問的db.* to [email protected]‘%‘ identified by ‘password’;  為了安全,代碼裡面別用root  

 

 

   第一種:

 增加一個使用者test1密碼為abc,讓他可以在任何主機上登入,並對所有資料庫有查詢、插入、修改、刪除的許可權。首先用以root使用者連入MYSQL,然後鍵入以下命令: 

mysql>grant select,insert,update,delete on *.* to [email protected]‘%‘  identified by ‘abc‘;

mysql>grant all privileges on *.* to [email protected]‘%‘ identified by ‘abc‘;

 

  但增加的使用者是十分危險的,你想如某個人知道test1的密碼,那麼他就可以在internet上的任何一台電腦上登入你的mysql資料庫並對你的資料可以為所欲為了,解決辦法見例第二種: 

  第一種:增加一個使用者test2密碼為abc,讓他只可以在localhost上登入,並可以對資料庫mydb進行查詢、插入、修改、刪除的操作(localhost指本地主機,即MYSQL資料庫所在的那台主機),這樣使用者即使用知道test2的密碼,他也無法從internet上直接存取數

mysql> grant select,insert,update,delete on book.* to [email protected] Identified by ’abc‘;

 

  如果你不想test2有密碼,可以再打一個命令將密碼消掉。 

mysql> grant select,insert,update,delete on book.* to [email protected] Identified by ’‘;

 

 

5:重啟mysql

[html] view plaincopy  
  1. /etc/init.d/mysql restart  

 

[html] view plaincopy  
  1. 卸載 mysql  
  2. sudo apt-get autoremove –purge mysql-server-5.5 //具體按TAB鍵提示  
  3. sudo apt-get remove mysql-server  
  4. sudo apt-get autoremove mysql-server  
  5. sudo apt-get remove mysql-common //這個很重要  

第二步:清理殘留資料

1  dpkg -l |grep ^rc|awk ‘{print $2}‘ |sudo xargs dpkg -P

 

查看是否安裝成功

tcp 0 0 localhost.localdomain:mysql *:* LISTEN -


如果伺服器不能正常運行,您可以通過下列命令啟動它:


1 sudo /etc/init.d/mysql restart


第四步:組態管理員密碼

進入mysql


1 $mysql -u root -p 管理員密碼


配置 MySQL 的管理員密碼:


1 sudo mysqladmin -u root password newpassword

ubuntu12.04 安裝和卸載mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.