0.说明 使用yum安装的好处是,你不用自己去解决软件之间的依赖问题,基本上yum执行完成,也就把软件安装好了,下面介绍使用yum的方法来安装MySQL,同时也会介绍安装完成后的安全优化。 注意:下面的操作都是以新安装的CentOS 6.5来作为演示的。CentOS 7下源码安装MySQL 5.6 http://www.linuxidc.com/Linux/2015-06/119354.htmMySQL5.7.3.0安装配置图解教程 http://www.linuxidc.com/Linux/2014-10/108397.htmUbuntu 14.04下安装MySQL http://www.linuxidc.com/Linux/2014-05/102366.htm《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF http://www.linuxidc.com/Linux/2014-03/98821.htmUbuntu 14.04 LTS 安装 LNMP NginxPHP5 (PHP-FPM)MySQL http://www.linuxidc.com/Linux/2014-05/102351.htmUbuntu 14.04下搭建MySQL主从服务器 http://www.linuxidc.com/Linux/2014-05/101599.htmUbuntu 12.04 LTS 构建高可用分布式 MySQL 集群 http://www.linuxidc.com/Linux/2013-11/93019.htmUbuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb http://www.linuxidc.com/Linux/2013-08/89270.htmMySQL-5.5.38通用二进制安装 http://www.linuxidc.com/Linux/2014-07/104509.htm
1.使用yum安装MySQL 如果你在安装CentOS的时候指定了安装MySQL数据库,就要有显示,这里我并没有安装MySQL。
注意在你的系统上查看安装成功后的提示信息。
| 12345 | [root@leaf ~]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 |
| 12 | [root@leaf ~]Starting mysqld: [ OK ] |
| 1234567891011121314 | [root@leaf ~]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用户创建密码| 1234567 | [root@leaf ~]mysql> update mysql.user set password = password("123456") where User = "root"; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) |
上面就为root用户创建了密码`123456`。
(2)删除匿名用户| 1234 | [root@leaf ~]Enter password: mysql> |
| 1234567 | 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)步之后再查看一下当前的账户信息:
| 123456789 | 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开头的数据库 操作如下:
| 12345678 | 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的基本安全优化就完成了,应该不会有太大的问题。
本文永久更新链接地址