標籤:mysql yum 安裝 安全 最佳化
0.說明
使用yum安裝的好處是,你不用自己去解決軟體之間的依賴問題,基本上yum執行完成,也就把軟體安裝好了,下面介紹使用yum的方法來安裝MySQL,同時也會介紹安裝完成後的安全最佳化。
注意:下面的操作都是以新安裝的CentOS 6.5來作為示範的。
1.使用yum安裝MySQL
[[email protected]]# yum list installed | grep mysql
如果你在安裝CentOS的時候指定了安裝MySQL資料庫,就要有顯示,這裡我並沒有安裝MySQL。
[[email protected] ~]# yum -y install mysql-server mysql mysql-devel
注意在你的系統上查看安裝成功後的提示資訊。
[[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
[[email protected] ~]# service mysqld startStarting mysqld: [ OK ]
[[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)刪除匿名使用者
[[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+安全最佳化