0755mx 发表于 2018-10-1 10:25:07

在CentOS上使用yum安装MySQL+安全优化

  0.说明
  使用yum安装的好处是,你不用自己去解决软件之间的依赖问题,基本上yum执行完成,也就把软件安装好了,下面介绍使用yum的方法来安装MySQL,同时也会介绍安装完成后的安全优化。
  注意:下面的操作都是以新安装的CentOS6.5来作为演示的。
  1.使用yum安装MySQL

[*]  查看是否已经安装MySQL:
# yum list installed | grep mysql  如果你在安装CentOS的时候指定了安装MySQL数据库,就要有显示,这里我并没有安装MySQL。

[*]  安装MySQL数据库:
# yum -y install mysql-server mysql mysql-devel  注意在你的系统上查看安装成功后的提示信息。

[*]  查看安装的MySQL信息:
# yum list installed | grep mysql  
mysql.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服务:
# service mysqld start  
Starting mysqld:                                          

[*]  登陆到MySQL数据库中:
# mysql  
Welcome to the MySQL monitor.Commands end with ; or \g.
  
Your MySQL connection id is 4
  
Server version: 5.1.73 Source distribution
  

  
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>
  其实如果是非生产环境要求的话,像上面这样使用yum简单安装就可以了,当然如果是用于生产环境的,那么建议还是使用源码安装。
  2.MySQL安全优化
  至于为什么要安全优化,可以看博主写的用源码安装MySQL的博文:《在CentOS上源码安装MySQL+安装问题解决+安全优化》
  下面就直接给出操作的步骤。(注意:要确保MySQL服务已经开启,上面已经给出方法)
  (1)为root用户创建密码
# mysql -u root  
mysql> update mysql.user set password = password('123456') where User = 'root';
  
Query OK, 3 rows affected (0.00 sec)
  
Rows matched: 3Changed: 3Warnings: 0
  

  
mysql> flush privileges;
  
Query OK, 0 rows affected (0.00 sec)
  上面就为root用户创建了密码`123456`。
  (2)删除匿名用户

[*]  先使用刚刚创建的密码登陆到MySQL中:
# mysql -u root -p  
Enter 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的基本安全优化就完成了,应该不会有太大的问题。


页: [1]
查看完整版本: 在CentOS上使用yum安装MySQL+安全优化