ubuntu 13.04 安裝mysql資料庫教程

來源:互聯網
上載者:User

   Ubuntu是一個流行的Linux作業系統,基於Debian發行版和GNOME案頭環境,和其他Linux發行版相比,Ubuntu非常易用,和Windows相容性很好,非常適合Windows使用者的遷移,預裝了大量常用軟體,中文版的功能也較全,支援拼音IME,預裝了firefox、Open Office、多媒體播放、影像處理等大多數常用軟體,一般會自動安裝網卡、音效卡等裝置的驅動。

   安裝MySQL   在Ubuntu上可以使用Ubuntu Software Center或者apt命令來安裝MySQL,兩種方式都十分方便。   1. 使用Ubuntu Software Center:開啟Ubuntu Software Center,在右上方的搜尋方塊查詢mysql,然後選定MySQL Server,點擊安裝即可。   2. 使用apt:開啟終端執行 ”sudo apt-get install mysql-server“ 即可。   MySQL初始配置   MySQL完成安裝後可以直接使用root賬戶登入,且該賬戶預設是沒有密碼的。注意這裡的root角色就是指你的Ubuntu的root角色,如果你當前使用的系統帳號不是root的話,也不必切換到系統root賬戶,可以在登入MySQL的時候使用“-u"這個參數來指定登入賬戶。如:   $ mysql -u root   mysql> show databases;   +--------------------+   | Database |   +--------------------+   | information_schema |   | mysql |   | performance_schema |   | test |   +--------------------+   4 rows in set (0.00 sec)   mysql> select Host, User from user;   +-----------+------------------+   | Host | User |   +-----------+------------------+   | 127.0.0.1 | root |   | ::1 | root |   | iUbuntu | |   | iUbuntu | root |   | localhost | |   | localhost | debian-sys-maint |   | localhost | root |   +-----------+------------------+   7 rows in set (0.00 sec)   因為此時root賬戶預設沒有密碼,所以不用輸入密碼就能以root角色登入並查看所有資訊的許可權。如果換成非root角色登入MySQL,則只擁有部分資料庫操作許可權。   $ mysql   mysql> show databases;   +--------------------+   | Database |   +--------------------+   | information_schema |   | test |   +--------------------+   2 rows in set (0.00 sec)   mysql> use mysql   ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'   因此MySQL完成安裝後的第一件事就是給root使用者佈建密碼,否則資料庫將毫無安全可言。   mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "";   將以上命令中的替換為你要設定的密碼,以上命令的意思是對在本機(localhost)使用密碼登入的root使用者賦予所有資料庫的操作許可權。設定密碼後,如果再以root使用者登入就需要輸入密碼了,如:   $ mysql -u root   ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)   $ mysql -u root -p   Enter password:   Welcome to the MySQL monitor. Commands end with ; or g.   Your MySQL connection id is 75   Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)   Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.   Oracle is a registered trademark of Oracle Corporation and/or its   affiliates. Other names may be trademarks of their respective   owners.   Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.   mysql>   建立資料庫獨立使用者   因為root使用者擁有資料庫的所有操作許可權,所以不能輕易地提供給別人使用。在一個MySQL執行個體中可以建立多個資料庫,這些資料庫可能歸屬於不同項目,每個資料庫的操作角色也不一樣。對此可以針對不同那個資料庫指定使用者進行訪問。   首先使用root角色建立一個資料庫   mysql> create database db_web_monitor   然後將這個資料庫授予一個叫xavier的使用者使用   mysql> GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@localhost IDENTIFIED BY "xavier";   這樣就可以使用xavier使用者,密碼為xavier在本機登入MySQL操作db_web_monitor資料庫了。   $ mysql -u xavier   ERROR 1045 (28000): Access denied for user 'xavier'@'localhost' (using password: NO)   $ mysql -u xavier -p   Enter password:   Welcome to the MySQL monitor. Commands end with ; or g.   Your MySQL connection id is 77   Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)   Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.   Oracle is a registered trademark of Oracle Corporation and/or its   affiliates. Other names may be trademarks of their respective   owners.   Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.   mysql> show databases;   +--------------------+   | Database |   +--------------------+   | information_schema |   | db_web_monitor |   | test |   +--------------------+   3 rows in set (0.00 sec)   mysql>   開放遠程登入許可權   1. 首先修改MySQL的設定檔,允許監聽遠程登入。   $ sudo vi /etc/mysql/my.cnf   找到bind-address所在行   45 # Instead of skip-networking the default is now to listen only on   46 # localhost which is more compatible and is not less secure.   47 bind-address = 127.0.0.1   將 bind-address值修改為本機IP即可。   注意注釋說明,如果是較老版本的MySQL,此處就應該是skip-networking,直接將其注釋即可。   2. 授予使用者遠程登入許可權。   mysql>GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@"%" IDENTIFIED BY "xavier";   如此這般,xavier使用者就可以在任意主機通過IP訪問到本機MySQL,對db_web_monitor資料庫進行操作了。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.