linux 安装rpm mysql

1.查看操作系统相关信息。

[[email protected] ~]# cat /etc/issue 
CentOS release 6.5 (Final) 
Kernel \r on an \m 
[[email protected] ~]# uname -a 
Linux linuxidc 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

2.创建需要下载rpm软件包的目录。
1 [[email protected] ~]# mkdir -p /taokey/tools

3.查看下是否有系统自带mysql的rpm包,如果有,需要删除自带的旧rpm包。
[[email protected] ~]# rpm -qa | grep mysql 
mysql-libs-5.1.71-1.el6.x86_64 
[[email protected] ~]# yum -y remove mysql-libs-5.1* 
[[email protected] ~]# rpm -qa | grep mysql 
[[email protected] ~]#

4.在MySQL官网下载安装MySQL-5.6.21所需的rpm软件包。
需要下载三个rpm软件包:
MySQL-client-5.6.21-1.rhel5.x86_64.rpm  
MySQL-devel-5.6.21-1.rhel5.x86_64.rpm  
MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
[[email protected] ~]# cd /taokey/tools/ 
[[email protected] tools]# wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
[[email protected] tools]# wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-devel-5.6.21-1.rhel5.x86_64.rpm 
[[email protected] tools]# wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.21-1.rhel5.x86_64.rpm

5.下载完之后,安装三个rpm软件包。
[[email protected] tools]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
error: Failed dependencies:
        libaio.so.1()(64bit) is needed by MySQL-server-5.6.21-1.rhel5.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.21-1.rhel5.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.21-1.rhel5.x86_64
安装MySQL-server报错,原因是没有安装libaio,系统缺少libaio.so此软件包,下边yum安装一下libaio.so软件包。
[[email protected] tools]# yum install -y libaio 
[[email protected] tools]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
[[email protected] tools]# rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm  
Preparing...                ########################################### [100%] 
  1:MySQL-client          ########################################### [100%] 
[[email protected] tools]# rpm -ivh MySQL-devel-5.6.21-1.rhel5.x86_64.rpm  
Preparing...                ########################################### [100%] 
  1:MySQL-devel            ########################################### [100%]

6.修改配置文件位置。
[[email protected] tools]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf

7.初始化MySQL及修改MySQL默认的root密码。
[[email protected] tools]# /usr/bin/mysql_install_db 
[[email protected] tools]# ps -ef | grep mysql 
root      2188    1  0 14:48 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/linuxidc.pid 
mysql    2303  2188 30 14:48 pts/1    00:00:02 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/linuxidc.err --pid-file=/var/lib/mysql/linuxidc.pid 
root      2331  1853  0 14:49 pts/1    00:00:00 grep mysql 
[[email protected] tools]# netstat -anpt | grep 3306 
tcp        0      0 :::3306                    :::*                        LISTEN      2303/mysqld
[[email protected] tools]# more /root/.mysql_secret 
# The random password set for the root user at Thu Apr  9 14:43:59 2015 (local time): F6K3v_xggFoLQeiN 
  
[[email protected] tools]# mysql -uroot -pF6K3v_xggFoLQeiN 
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 1 
Server version: 5.6.21 
  
Copyright (c) 2000, 2014, 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('123.com');  
mysql> exit
Bye 
[[email protected] tools]# mysql -uroot -p123.com 
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 6 
Server version: 5.6.21 MySQL Community Server (GPL) 
  
Copyright (c) 2000, 2014, 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>

8.设置MySQL服务开机自启动。
[[email protected] tools]# chkconfig mysql on 
[[email protected] tools]# chkconfig mysql --list 
mysql          0:off  1:off  2:on    3:on    4:on    5:on    6:off

到此为止,使用RPM安装MySQL5.6版本数据库安装完毕,谢谢大家。

CentOS 6.5下安装MySQL 5.6.21  http://www.linuxidc.com/Linux/2015-01/111413.htm



  1. 查找以前是否安装有mysql,使用下面命令:

    rpm -qa|grep -i mysql

    如果显示有如下包则说明已安装mysql

    mysql-4.1.12-3.RHEL4.1

    mysqlclient10-3.23.58-4.RHEL4.1

  2. 如果已安装,则需要删除已安装的数据库,使用以下命令来删除数据库

    删除命令:rpm -e --nodeps 包名

    ( rpm -ev mysql-4.1.12-3.RHEL4.1 )

    删除老版本mysql的开发头文件和库

    命令:rm -fr /usr/lib/mysql

    rm -fr /usr/include/mysql

    注意:卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除

    rm -f /etc/my.cnf

    rm -fr /var/lib/mysql

  3. 下载mysql的rpm包

    可以通过wget下载具体的地址因为不能用链接请大家去官网去找

    (1)MySQL-server-5.6.10-1.rhel5.x86_64.rpm:MySQL服务器;

    (2)MySQL-client-5.6.10-1.rhel5.x86_64.rpm:MySQL客户端;

    (3)MySQL-devel-5.6.10-1.rhel5.x86_64.rpm:Mysql开发依赖包。

    下载后放到Liunx服务器中,如图所示

    linux 安装rpm mysql
  4. 安装MySQL Server的rpm包

    rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm

    安装过程如图所示

    安装完成后会生成root用户的随机密码,请使用“cat /root/.mysql_secret”或类似命令进行查看。

    linux 安装rpm mysql
    linux 安装rpm mysql
  5. 安装MySQL客户端

    rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm

    linux 安装rpm mysql
  6. 安装MySQL开发依赖包

    rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm

    linux 安装rpm mysql
  7. 启动msyql

    安装完成后mysql是没有启动的,运行mysql命令会提示如下错误:

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    可使用如下命令启动MySQL:

    service mysql start

    或者使用如下命令:

    /etc/init.d/mysql start

    可使用SET PASSWORD命令修改root用户的密码,参考如下:SET PASSWORD = PASSWORD('root123456');

    linux 安装rpm mysql
    linux 安装rpm mysql
  8. 登录MySQL

    使用mysql命令登录MySQL服务器,运行MySQL的命令时,会提示需要设置root用户密码

    linux 安装rpm mysql
  9. 设置开机自启动

    /etc/init.d/mysql start

    设置完成后重启系统,使用natstat –nat命令可看到MySQL的3306端口

  10. 至此我们已经安装好了mysql数据库,当然现在我们的数据库还不支持远程连接,远程连接会出现以下代码:1130,ERROR 1130: Host 192.168.0.10 is not allowed to connect to this MySQL server,可以通过以下以下来解决

  11. 改表法:在本机登入mysql后,更改“mysql”数据库里的“user”表里的“host”项,从”localhost”改为'%'。

    mysql>

    mysql>use mysql;

    mysql>select 'host' from user where user='root';        

  12. 12

    好了,开始享受mysql带来的强大功能吧