在CentOS上使用yum安裝MySQL+安全最佳化

來源:互聯網
上載者:User

標籤:mysql   yum   安裝   安全   最佳化   

0.說明

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

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



1.使用yum安裝MySQL

        

  • 查看是否已經安裝MySQL:

[[email protected]]# yum list installed | grep mysql

        如果你在安裝CentOS的時候指定了安裝MySQL資料庫,就要有顯示,這裡我並沒有安裝MySQL。

  • 安裝MySQL資料庫:

[[email protected] ~]# yum -y install mysql-server mysql mysql-devel

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

  • 查看安裝的MySQL資訊:

[[email protected] ~]# yum list installed | grep mysqlmysql.x86_64            5.1.73-5.el6_6  @base                                   mysql-devel.x86_64      5.1.73-5.el6_6  @base                                   mysql-libs.x86_64       5.1.73-5.el6_6  @base                                   mysql-server.x86_64     5.1.73-5.el6_6  @base
  • 開啟MySQL服務:

[[email protected] ~]# service mysqld startStarting mysqld:                                           [  OK  ]
  • 登陸到MySQL資料庫中:

[[email protected] ~]# mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, 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>


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



2.MySQL安全最佳化


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

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


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

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

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


(2)刪除匿名使用者

  • 先使用剛剛建立的密碼登陸到MySQL中:

[[email protected] ~]# mysql -u root -pEnter password:mysql>
  • 刪除匿名使用者:

mysql> DROP USER ‘‘@‘localhost‘;Query OK, 0 rows affected (0.00 sec)mysql> DROP USER ‘‘@‘leaf‘;     Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

        注意第二條刪除語句的`leaf`,在這裡,`leaf`為我的主機名稱,按照你的實際情況進行操作即可。


        執行完上面(1)(2)步之後再查看一下當前的賬戶資訊:

mysql> select User, Host, Password from mysql.user; +------+-----------+-------------------------------------------+| User | Host      | Password                                  |+------+-----------+-------------------------------------------+| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root | leaf      | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+------+-----------+-------------------------------------------+3 rows in set (0.00 sec)


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

        操作如下:

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


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


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

在CentOS上使用yum安裝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.