RedHat5.8下RPM包方式安装MySQL5.6
1. 安装环境
操作系统:Linux RH5.8-64bit 2.6.18-308.el5
配置:2CPU、4G内存
2. 安装准备
1) 安装包下载
从MySQL官网下载Community Server版的安装包:
下载地址:http://dev.mysql.com/downloads/mysql/#downloads
图1
平台选择Oracle & Red Hat Linux 4&5,下载下面两个安装包:
MySQL-server-5.6.14-1.rhel5.x86_64.rpm
MySQL-client-5.6.14-1.rhel5.x86_64.rpm
2) 文档参考
官方参考文档:
http://dev.mysql.com/doc/refman/5.6/en/linux-installation-rpm.html
3) 注意事项
安装时用户必须是root,在MySQL 安装时,会创建mysql 用户和mysql组。
3. 安装过程
下面的安装操作是在root用户下进行
1) 安装文件存放目录
创建存放目录:
[root@RH5 ~]# cd /tmp
[root@RH5 tmp]# mkdir mysql_setup
将安装文件放到该目录下面
2) 安装Server端
[root@RH5 tmp]# cd mysql_setup/
[root@RH5 mysql_setup]# ll
总计 30016
-rw-r--r-- 1 root root 21738371 10-10 12:27 MySQL-client-5.6.14-1.rhel5.x86_64.rpm
-rw-r--r-- 1 root root 8940296 10-10 11:59 MySQL-server-5.6.14-1.rhel5.x86_64.rpm
[root@RH5 mysql_setup]# rpm -ivh MySQL-server-5.6.14-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
Giving mysqld 5 seconds to exit nicely
1:MySQL-server ########################################### [100%]
2013-10-12 15:57:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-10-12 15:57:47 9044 [Note] InnoDB: The InnoDB memory heap is disabled
2013-10-12 15:57:47 9044 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-10-12 15:57:47 9044 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-10-12 15:57:47 9044 [Note] InnoDB: Using Linux native AIO
2013-10-12 15:57:47 9044 [Note] InnoDB: Using CPU crc32 instructions
2013-10-12 15:57:47 9044 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-10-12 15:57:47 9044 [Note] InnoDB: Completed initialization of buffer pool
2013-10-12 15:57:47 9044 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2013-10-12 15:57:47 9044 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2013-10-12 15:57:47 9044 [Note] InnoDB: Database physically writes the file full: wait...
2013-10-12 15:57:48 9044 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2013-10-12 15:57:50 9044 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2013-10-12 15:57:56 9044 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2013-10-12 15:57:56 9044 [Warning] InnoDB: New log files created, LSN=45781
2013-10-12 15:57:56 9044 [Note] InnoDB: Doublewrite buffer not found: creating new
2013-10-12 15:57:56 9044 [Note] InnoDB: Doublewrite buffer created
2013-10-12 15:57:56 9044 [Note] InnoDB: 128 rollback segment(s) are active.
2013-10-12 15:57:56 9044 [Warning] InnoDB: Creating foreign key constraint system tables.
2013-10-12 15:57:56 9044 [Note] InnoDB: Foreign key constraint system tables created
2013-10-12 15:57:56 9044 [Note] InnoDB: Creating tablespace and datafile system tables.
2013-10-12 15:57:56 9044 [Note] InnoDB: Tablespace and datafile system tables created.
2013-10-12 15:57:56 9044 [Note] InnoDB: Waiting for purge to start
2013-10-12 15:57:56 9044 [Note] InnoDB: 5.6.14 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2013-10-12 15:57:57 9044 [Note] Binlog end
2013-10-12 15:57:57 9044 [Note] InnoDB: FTS optimize thread exiting.
2013-10-12 15:57:57 9044 [Note] InnoDB: Starting shutdown...
2013-10-12 15:57:59 9044 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2013-10-12 15:57:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-10-12 15:57:59 9067 [Note] InnoDB: The InnoDB memory heap is disabled
2013-10-12 15:57:59 9067 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-10-12 15:57:59 9067 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-10-12 15:57:59 9067 [Note] InnoDB: Using Linux native AIO
2013-10-12 15:57:59 9067 [Note] InnoDB: Using CPU crc32 instructions
2013-10-12 15:57:59 9067 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-10-12 15:57:59 9067 [Note] InnoDB: Completed initialization of buffer pool
2013-10-12 15:57:59 9067 [Note] InnoDB: Highest supported file format is Barracuda.
2013-10-12 15:57:59 9067 [Note] InnoDB: 128 rollback segment(s) are active.
2013-10-12 15:57:59 9067 [Note] InnoDB: Waiting for purge to start
2013-10-12 15:57:59 9067 [Note] InnoDB: 5.6.14 started; log sequence number 1625977
2013-10-12 15:58:00 9067 [Note] Binlog end
2013-10-12 15:58:00 9067 [Note] InnoDB: FTS optimize thread exiting.
2013-10-12 15:58:00 9067 [Note] InnoDB: Starting shutdown...
2013-10-12 15:58:01 9067 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
以上为安装过程中的输出内容。
3) 安装Client端
[root@RH5 mysql_setup]# rpm -ivh MySQL-client-5.6.14-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
4) 安装成功后mysql相关目录
Directory |
Contents of Directory |
/usr/bin |
Client programs and scripts |
/usr/sbin |
The mysqld server |
/var/lib/mysql |
Log files, databases |
/usr/share/info |
Manual in Info format |
/usr/share/man |
Unix manual pages |
/usr/include/mysql |
Include (header) files |
/usr/lib/mysql |
Libraries |
/usr/share/mysql |
Miscellaneous support files, including error messages character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench |
Benchmarks |
5) 查看安装后创建的mysql用户和mysql组信息
[root@RH5 mysql_setup]# grep mysql /etc/group
mysql:x:157:
[root@RH5 mysql_setup]# grep mysql /etc/passwd
mysql:x:101:157:MySQL server:/var/lib/mysql:/bin/bash
4. 更改root密码
默认mysql服务不启动,可输入mysql命令验证,显示mysql服务没有启动
[root@RH5 mysql_setup]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
启动mysql服务
[root@RH5 mysql_setup]# service mysql start
Starting MySQL. [确定]
[root@RH5 mysql_setup]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
查看临时密码:
[root@RH5 mysql_setup]# vi /root/.mysql_secret
# The random password set for the root user at Sat Oct 12 15:57:57 2013 (local time): 1im7ekAa
使用临时密码登陆
[root@RH5 mysql_setup]# mysql -uroot -p1im7ekAa
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.14
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> set password=Password('123456');
Query OK, 0 rows affected (0.00 sec)
将root用户密码修改成123456,在实际应用中,密码要设置更复杂些。
5. 设置开机自启动
[root@RH5 mysql_setup]# chkconfig --list|grep mysql
mysql 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
0表示:表示关机
1表示:单用户模式
2表示:无网络连接的多用户命令行模式
3表示:有网络连接的多用户命令行模式
4表示:不可用
5表示:带图形界面的多用户模式
6表示:重新启动
MySQL服务器主要在级别3或5情况下运行,从上面的情况可以看到现在符合开机自启动要求。
设置开启不自启动
[root@RH5 mysql_setup]# chkconfig mysql off
[root@RH5 mysql_setup]# chkconfig --list|grep mysql
mysql 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
设置开机自启动
[root@RH5 mysql_setup]# chkconfig mysql on
[root@RH5 mysql_setup]# chkconfig --list|grep mysql
mysql 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
6. 建立新的数据库和用户
用root用户登录,并查看当前的数据库
[root@RH5 mysql_setup]# mysql -uroot -p123456
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
创建名称为moli的数据库
mysql> CREATE SCHEMA IF NOT EXISTS `moli` DEFAULT CHARACTER SET utf8 ;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| moli |
| test |
+--------------------+
5 rows in set (0.00 sec)
创建用户yang,密码也是yang,该用户对数据库moli有所有的执行权限,并且在任何终端下都可以访问该数据库。
mysql> grant all privileges on moli.* to 'yang'@'%' identified by 'yang' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
这样设置只是开发用,在实际生产中,对用户的权限、可访问终端都要做严格的限制,不要这样分配。
使用刚建立的用户yang在本地登录:
[root@RH5 mysql_setup]# mysql -uyang –pyang
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| moli |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> use moli;
Database changed
mysql> show tables;
Empty set (0.00 sec)
7. 设置远程端口访问
查看防火墙状态
[root@RH5 mysql_setup]# service iptables status
防火墙已停
现在防火墙处于关闭状态,在这种情况下可以进行远程访问该数据库,下面用Windows客户端做的测试,可以正常登陆。
C:\Users\lify>mysql -uyang -pyang -h 192.168.1.100
MySQL启用的默认端口为3306,可以通过下面命令查看:
[root@RH5 mysql_setup]# netstat -nat|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.100:3306 192.168.1.200:50140 ESTABLISHED
上面显示一个客户端正通过3306端口在连接MySQL。
在防火墙开启情况下,设置MySQL的远程访问。
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
# 查看规则是否生效
iptables -L -n # 或者: service iptables status
上面iptables添加/删除规则都是临时的
service iptables save 或者: /etc/init.d/iptables save进行保存。
#删除规则如下
iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables save
至此,MysQL安装已经完毕,但这只是开发环境下所有,在实际生产中,还要做更多的设置。