CentOS-minimal 6.5 安装mysql

CentOS-minimal 6.5 安装mysql

之前写了一个在Ubuntu上使用离线包安装mysql的过程,相较于CentOS来说稍微麻烦点,因为mysql提供了rpm安装包。

在安装之前,我们先把所需的安装包下载下来,使用的版本还是5.5.45,与Ubuntu离线包的区别是,这里我们要下载三个安装包,下载链接如下:

http://cdn.mysql.com/archives/mysql-5.5/MySQL-server-5.5.45-1.linux2.6.x86_64.rpm

http://cdn.mysql.com/archives/mysql-5.5/MySQL-client-5.5.45-1.linux2.6.x86_64.rpm

http://cdn.mysql.com/archives/mysql-5.5/MySQL-devel-5.5.45-1.linux2.6.x86_64.rpm

这里还是建议使用迅雷下载,下载完成后待用。

  • 首先,我使用的CentOS是minimal6.5版本的,查看是否安装了mysql:
    [root@qiuxiao ~]# rpm -qa | grep mysql
    mysql-libs-5.1.71-1.el6.x86_64
  • 此版本默认安装了mysql-libs(其他版本我也看过了,安装的更多),先把它卸载掉,否则后面安装不了:
    [root@qiuxiao ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
  • 在安装之前先安装一个依赖包,mysql运行的时候会用到这个依赖包,否则运行不了:
    [root@qiuxiao ~]# yum install libaio
  • 安装mysql,安装顺序如下(别忘了先上传到CentOS上,我是上传到/usr/local/目录下),注意输出的信息,会用到的:
    [root@qiuxiao local]# rpm -ivh MySQL-server-5.5.45-1.linux2.6.x86_64.rpm
    warning: MySQL-server-5.5.45-1.linux2.6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-server           ########################################### [100%]
    151020 19:14:16 [Note] /usr/sbin/mysqld (mysqld 5.5.45) starting as process 1240 ...
    151020 19:14:16 [Note] /usr/sbin/mysqld (mysqld 5.5.45) starting as process 1247 ...

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

    /usr/bin/mysqladmin -u root password 'new-password'
    /usr/bin/mysqladmin -u root -h qiuxiao password 'new-password'

    Alternatively you can run:
    /usr/bin/mysql_secure_installation

    which will also give you the option of removing the test
    databases and anonymous user created by default.  This is
    strongly recommended for production servers.

    See the manual for more instructions.

    Please report any problems at http://bugs.mysql.com/

    [root@qiuxiao local]# rpm -ivh MySQL-client-5.5.45-1.linux2.6.x86_64.rpm
    warning: MySQL-client-5.5.45-1.linux2.6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-client           ########################################### [100%]

    [root@qiuxiao local]# rpm -ivh MySQL-devel-5.5.45-1.linux2.6.x86_64.rpm
    warning: MySQL-devel-5.5.45-1.linux2.6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-devel            ########################################### [100%]
  • 启动mysql服务:
    [root@qiuxiao local]# service mysql start
    Starting MySQL.. SUCCESS!
  • 修改root密码:
    [root@qiuxiao local]# /usr/bin/mysqladmin -u root password 'new password'
  • 登录mysql:

    [root@qiuxiao local]# mysql -u root -p
    Enter password: 
  • 设置字符集
    1)查询字符集:

    mysql> show variables like'character%';

    CentOS-minimal 6.5 安装mysql_第1张图片

    2)修改字符集:

    mysql> SET character_set_database = utf8;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SET character_set_server = utf8;
    Query OK, 0 rows affected (0.00 sec)
  • 设置root用户可以远程连接(以下两种任选其一)
    1)从所有主机:

    mysql> grant all privileges on *.* to root@"%" identified by"root用户的密码"with grant option;
    Query OK, 0 rows affected (0.00 sec)

    2)从指定主机:

    mysql> grant all privileges on *.* to root@"192.168.11.205" identified by"root用户的密码"with grant option; flush privileges;
    Query OK, 0 rows affected (0.00 sec)
  • 重启mysql服务

    [root@qiuxiao ~]# service mysql restart
    Shutting down MySQL... SUCCESS! 
    Starting MySQL.. SUCCESS!
  • 防火墙开放mysql端口3306
    1)开放3306端口:

    [root@qiuxiao ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

    2)保存:

    [root@qiuxiao ~]# /etc/rc.d/init.d/iptables save
    iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

    3)重启防火墙:

    [root@qiuxiao ~]# /etc/init.d/iptables restart
    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    iptables: Flushing firewall rules:                         [  OK  ]
    iptables: Unloading modules:                               [  OK  ]
    iptables: Applying firewall rules:                         [  OK  ]
  • Navicat连接mysql
    CentOS-minimal 6.5 安装mysql_第2张图片

CentOS-minimal 6.5 安装mysql_第3张图片

由图可知,连接成功!
CentOS-minimal 6.5 安装mysql_第4张图片

你可能感兴趣的:(ubuntu,CentOS,mysql)