在Ubuntu上使用apt-get安裝MySQL+安全最佳化

來源:互聯網
上載者:User

標籤:安裝   mysql   最佳化   安全   apt-get   

0.說明

        使用apt-get安裝的好處是,你不用自己去解決軟體之間的依賴問題,基本上apt執行完成,也就把軟體安裝好了,下面介紹使用apt的方法來安裝MySQL,同時也會介紹安裝完成後的安全最佳化。

        注意:下面的操作都是以新安裝的Ubuntu 15.10來作為示範的。



1.使用apt安裝MySQL

        

  • 安裝MySQL資料庫:

        注意:在安裝過程中會幾次要求你設定MySQL資料庫的管理使用者密碼,我們這裡先不設定。(出現要求設定的頁面時直接按“確定”即可。)

[email protected]:~$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev

        注意在你的系統上查看安裝成功後的提示資訊。

  • 開啟MySQL服務:

[email protected]:~$ sudo service mysql start
  • 登陸到MySQL資料庫中:

[email protected]:~$ mysql -u rootWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 7Server version: 5.6.28-0ubuntu0.15.10.1 (Ubuntu)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>

        由於在安裝的時候並沒有為MySQL資料庫的root使用者佈建密碼,所以這裡不用輸入密碼就可以進入到MySQL資料庫中了。


        其實如果是非生產環境要求的話,像上面這樣使用apt-get簡單安裝就可以了,當然如果是用於生產環境的,那麼建議還是使用源碼安裝。



2.MySQL安全最佳化


        至於為什麼要安全最佳化,可以看博主寫的用源碼安裝MySQL的博文:《在CentOS上源碼安裝MySQL+安裝問題解決+安全最佳化》

        下面就直接給出操作的步驟。(注意:要確保MySQL服務已經開啟,上面已經給出方法)


(1)為root使用者建立密碼

[email protected]:~$ mysql -u rootmysql> update mysql.user set password = password(‘123456‘) where User = ‘root‘;mysql> update mysql.user set password = password(‘123456‘) where User = ‘root‘;Query OK, 4 rows affected (0.00 sec)Rows matched: 4  Changed: 4  Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

        上面就為root使用者建立了密碼`123456`。

        執行完之後再查看一下當前的賬戶資訊:

mysql>  select User, Host, Password from mysql.user; +------------------+-----------+-------------------------------------------+| User             | Host      | Password                                  |+------------------+-----------+-------------------------------------------+| root             | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root             | leaf      | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root             | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root             | ::1       | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || debian-sys-maint | localhost | *6A368D614E978D78292FC3257D3958C6A7B241EF |+------------------+-----------+-------------------------------------------+5 rows in set (0.00 sec)


        需要注意的是,由於我們已經為root使用者佈建了密碼,所以在下次登陸的時候請指定-p參數:

[email protected]:~$ mysql -u root -pEnter password:

        密碼就是我們設定的`123456`。


(2)刪除test資料庫或名字以test開頭的資料庫

        操作如下:

mysql> delete from mysql.db where db like ‘test%‘;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)


        OK,到這裡的話,使用apt-get安裝MySQL以及MySQL的基本安全最佳化就完成了,應該不會有太大的問題。

        

本文出自 “香飄葉子” 部落格,請務必保留此出處http://xpleaf.blog.51cto.com/9315560/1748704

在Ubuntu上使用apt-get安裝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.