CentOS-7下安装MySQL5.6.22(转发)

一 安装环境

(1)CentOS版本:CentOS-7

查看方法:

[[email protected] 桌面]# cat /etc/redhat-release

CentOS Linux release 7.0.1406 (Core)

来源:官网下载

下载地址:http://www.centos.org/

(2)MySQL版本:MySQL-5.6.22

来源:官网下载

下载地址:https://edelivery.oracle.com/EPD/Search/handle_go

或者http://pan.baidu.com/s/1dDu6n9R

名称:MySQL Database 5.6.22 RPM for Oracle Linux / RHEL 7 x86 (64bit)

二 安装方式选择

在网上搜了一下,Linux下安装MYSQL有三种方式:

1 通过yum命令在线下载安装

2 下载离线rpm安装包安装

3 下载源码编译安装

方式1不打算用,因为我们大部分项目服务器是不能直接上Internet的,网上关于在线安装的教程很多,方式3对于只要应用MYSQL的人来说没必要多此一举。

三 安装步骤

1. 解压下载的zip包,会发现有以下几个rpm包:

MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-embedded-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-test-advanced-5.6.22-1.el7.x86_64.rpm

2. 卸载MariaDB

如果直接点击rpm包安装会得到错误提示。因为CentOS的默认数据库已经不再是MySQL了,而是MariaDB,为什么呢?

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

查看当前安装的mariadb包:

[[email protected] 桌面]# rpm -qa | grep mariadb

将它们统统强制性卸载掉:

[[email protected] 桌面]# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64

[[email protected] 桌面]# rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64

[[email protected] 桌面]# rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64

3. 安装MYSQL

双击下面三个包进行自动安装:

MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm

MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm

提示:其实第二个包devel我也不知道是干什么的,也不知道是不是必须的(上网搜了一下应该不是必须的),没有测试是否必须就已经点来装上了,也不想花时间去测试是否必须了,有测试过的朋友麻烦留言告知。

4. 启动MYSQL

[[email protected] 桌面]#service mysql start

得到错误:ERROR!The server quit without updating PID file

我们这里主要是因为:selinux惹的祸,如果是centos系统,默认会开启selinux。解决方法是关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器。

然后再启动mysql就没问题了:

[[email protected] 桌面]#service mysql start

查看MySQL运行状态:

[[email protected] 桌面]# service mysql status

SUCCESS! MySQL running (2377)

5. 默认root用户登录MYSQL

如果安装过程并没有设置密码 通过mysql -u root

可以进入MySQL,则可以设置一个密码通过命令

set password=password(‘新密码‘);

安装中设置了密码则:

[[email protected] 桌面]# mysql -u root -p

Enter password:

ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: YES)

发现有有错误,然后在网上查了一下说使用下面命令修改root初始化密码:

[[email protected] 桌面]# /usr/bin/mysqladmin -u root password ‘passok‘

/usr/bin/mysqladmin: connect to server at‘localhost‘ failed

error: ‘Accessdenied for user ‘root‘@‘localhost‘ (using password: NO)‘

发现MYSQL数据库默认的root用户还是没办法设置密码进行登录,需要做一下操作:

重置MySQL中root用户密码及验证

还是不行,然后在网上又找到一个重置MySQL中root用户密码及验证的方法:

(1) 停止MySQL服务

[[email protected] 桌面]# service mysql stop

Shutting down MySQL.. SUCCESS!

(2) 输入绕过密码认证命令

[[email protected] 桌面]# mysqld_safe --user=mysql --skip-grant-tables--skip-networking &

[1] 5807

150117 22:23:31 mysqld_safe Logging to ‘/var/lib/mysql/bogon.err‘.

150117 22:23:31 mysqld_safe Starting mysqlddaemon with databases from /var/lib/mysql

(3) 输入登录用户命令

[[email protected] 桌面]# mysql -u root mysql

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version:5.6.22-enterprise-commercial-advanced MySQL Enterprise Server - AdvancedEdition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.

(4) 输入修改root密码SQL语句

mysql> UPDATEuser SET Password=PASSWORD(‘passok‘) where USER=‘root‘;

Query OK, 4 rows affected (0.04 sec)

Rows matched: 4 Changed: 4 Warnings: 0

(5) 输入数据刷新命令

mysql> FLUSHPRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

(6) 退出

mysql> quit

Bye

(7) 启动MYSQL

[[email protected] 桌面]# service mysql start

Starting MySQL SUCCESS!

登录mysql,查看所有数据库:

[[email protected] 桌面]# mysql -u root -p

mysql> show databases;

ERROR 1820 (HY000):You must SET PASSWORD before executing this statement

还是有错误啊,提示要再设置一下密码:

mysql> SETPASSWORD = PASSWORD(‘passok‘);

Query OK, 0 rows affected (0.00 sec)

显示数据库:

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.00 sec)

进入数据库创建表、显示表:

mysql> use test;

Database changed

mysql> show tables;

Empty set (0.02 sec)

mysql>create table testTable(name char(15) not null,passwd char(15) not null);

Query OK, 0 rows affected (0.87 sec)

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| testTable |

+----------------+

1 row in set (0.00 sec)

备注:我的设置的密码是“passok”。大家在执行showdatabases收到错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement后也可以试试以下面方式登录mysql来执行showdatabases是否就不会有这个错误,我没有条件测试了:

登录MySQL界面:mysql –uroot -p(修改的新密码)

例如:mysql -u root -p123456

mysql安装后三个主要的目录及其功能:

/var/lib/mysql 数据库文件

/usr/share/mysql 命令及配置文件

/usr/bin mysqladmin、mysqldump等命令

6. windows7上使用workbench连接到远端MySQL Server

(1) 下载安装workbench(MySQL Workbench 6.2.4 MSI for Windows x86(64bit))

(2) Windows下安装mysql workbench需要具备以下环境:

Microsoft .NET Framework 4 Client Profile

Microsoft Visual C++ 2013 RedistributablePackage (x64)

第一个就不用说了,第二个下载地址在:

http://www.microsoft.com/zh-CN/download/details.aspx?id=40784

(3)安装完成之后打开,进行连接配置:

发现连不上。

打开cmd命令行输入telnet 192.168.1.108 3306也提示连接不上(BTY:windows7默认没有安装telnet,需要通过控制面板中的打开或者关闭windows功能来打开telnet客户端功能)。

如果要想远端访问MYSQL数据库,还需要:

(1) 给指定用户赋予远端访问mysql数据库的权限;

(2) 配置防火墙放开对3306端口的限制;

1给指定用户赋予远端访问mysql数据库的权限

授权命令是:

grant 权限1,权限2,…权限n on 数据库名.表名 to用户名@用户地址 identified by‘口令’

[[email protected] 桌面]# mysql -uroot-ppassok -e "GRANT ALL PRIVILEGES ON *.* TO‘root‘@‘%‘ IDENTIFIED BY ‘passok‘ WITH GRANT OPTION;"

Warning: Using a password on the commandline interface can be insecure.

用root用户的身份执行grant命令(-e参数表示执行一段sql命令),含义是:把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。如果你只想让位于192.168.1.108机器上面的root用户访问,命令如下:

mysql -uroot -ppassok -e "GRANT ALL PRIVILEGES ON *.* TO‘root‘@‘192.168.1.108‘ IDENTIFIED BY ‘passok‘ WITH GRANT OPTION;"

2 配置防火墙放开3306端口的限制

CentOS 7.0版本的防火墙,默认使用的是firewall,与之前的版本使用iptables是不一样,经过我的测试,只要firewall处于开启状态,就不可能远端访问MYSQL数据库。

首先将firewall关闭:

[[email protected] 桌面]# systemctl stop firewalld.service #停止firewall

[[email protected] 桌面]# systemctl disable firewalld.service #禁止firewall开机启动

CentOS虽然默认的不是iptables,但是也是已经安装好的,然后我按照网上的方法,为3306端口配置开放规则:

[[email protected] 桌面]# vi /etc/sysconfig/iptables

# sample configuration for iptables service

# you can edit this manually or usesystem-config-firewall

# please do not ask us to add additionalports/services to this default configuration

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --stateRELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-ARH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp--dport 22 -j ACCEPT

-A INPUT -j REJECT --reject-withicmp-host-prohibited

-A FORWARD -j REJECT --reject-withicmp-host-prohibited

COMMIT

然后重启防火墙:

[[email protected] 桌面]# service iptables restart

然后立刻用mysql workbench测试,发现还是一样连不上。

然后执行下面命令永久关闭iptables:

[[email protected] bin]# chkconfig iptables off

注意:正在将请求转发到“systemctl disable iptables.service”。

然后立刻用mysql workbench测试,发现还是一样连不上。

重启CentOS系统,连接成功

看来要重启才能生效。

进一步测试:

查看firewall状态是关闭的:

[[email protected] bin]# service firewall status

Redirecting to /bin/systemctl status firewall.service

firewall.service

Loaded: not-found (Reason: No such file or directory)

Active: inactive (dead)

查看iptables状态也是关闭的:

[[email protected] bin]# service iptables status

Redirecting to /bin/systemctl status iptables.service

iptables.service - IPv4 firewall withiptables

Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled)

Active: inactive (dead)

然后我又启动iptables防火墙,还是能够访问,然后把/etc/sysconfig/iptables中的规则全部注释掉之后,还是能够访问,重启还是可以,不知道为什么,查看iptables的状态也是处于激活状态的:

[[email protected]]# service iptables status

Redirecting to /bin/systemctl status iptables.service

iptables.service - IPv4 firewall withiptables

Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled)

Active: active (exited) since 日 2015-01-1818:17:07 CST; 20s ago

Process: 14440 ExecStop=/usr/libexec/iptables/iptables.init stop(code=exited, status=0/SUCCESS)

Process: 14648 ExecStart=/usr/libexec/iptables/iptables.init start(code=exited, status=0/SUCCESS)

MainPID: 14648 (code=exited, status=0/SUCCESS)

1月 18 18:17:07 bogoniptables.init[14648]: iptables: Applying firewall rules: [ 确定 ]

1月 18 18:17:07 bogonsystemd[1]: Started IPv4 firewall with iptables.

反正永久关闭iptables防火墙是可以的,但是记得要重启。

7. 设置mysql开机自启动

设置开机启动服务选择使用chkconfig命令,可以看到我们永久性关闭iptables就用的这个命令,命令的格式如下:

chkconfig 功能说明:检查,设置系统的各种服务。

语法:chkconfig [--add][--del][--list][系统服务]或 chkconfig [--level <等级代号>][系统服务][on/off/reset]

--add 添加服务

--del 删除服务

--list 查看各服务启动状态

我这里安装好了mysql之后默认就是开机自启动的:

[[email protected] 桌面]# chkconfig --list mysql

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。

如果您想列出 systemd 服务,请执行 ‘systemctl list-unit-files‘。

欲查看对特定 target 启用的服务请执行

‘systemctl list-dependencies [target]‘。

mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关

如果不是开机自启动,使用开启MySQL服务自动开启命令:

chkconfig mysqld on

chkconfig mysql on

时间: 2024-08-05 15:18:30

CentOS-7下安装MySQL5.6.22(转发)的相关文章

CentOS-7下安装MySQL5.6.22

CentOS7下安装MySQL5.6.22(当前最新版本:2015-01-17) 转载请注明出处:jiq?钦's technical Blog 一  安装环境 (1)CentOS版本:CentOS-7 查看方法: [[email protected] 桌面]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) 来源:官网下载 下载地址:http://www.centos.org/ (2)MySQL版本:MySQL-5.6.2

CentOS-7下安装MySQL5.6.22(转)

转: http://www.2cto.com/database/201501/371451.html 一 安装环境 (1)CentOS版本:CentOS-7 查看方法: [[email protected] 桌面]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) 来源:官网下载 下载地址:http://www.centos.org/ (2)MySQL版本:MySQL-5.6.22 来源:官网下载 下载地址:https:/

centos系统下安装MySQL5.7.18

1.首先安装依赖包 yum install -y gcc gcc-c++ ncurses-devel perl openssl-devel 最最重要的是,不要忘了安装openssl-devel 2.安装cmake tar -xzvf cmake-3.8.1.tar.gz   cd cmake-3.8.1  ./bootstrapmake && make install 3.安装MySQL5.7.18 首先下载安装包,本人的安装版本是:mysql-boost-5.7.18.tar.gz 需要

centos6.7下安装mysql5.6.22同时解决中文乱码问题

1.下载 http://dev.mysql.com/downloads/mysql/ 或者使用wget下载: wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.22-1.el6.i686.rpm-bundle.tar 2.安装 2.1.  检测是否已经安装了mysql rpm -qa | grep mysql 如果已经安装了,将其卸载,如: rpm -e --nodeps  mysql-libs-5.1.71-1.el6.x8

centos 7 下安装mysql5.7

centos下默认安装mariadb数据库 1:将mariadb移除 yum search mysql; yum remove mariadb-libs.x86_64; 2:下载mysql源 wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm; 3:安装源 yum localinstall mysql57-community-release-el7-11.noarch.rpm; yum search

CentOS 5.5下安装mysql5.1.57+php5.2.17(FastCGI)+nginx1.0.1高性能Web服务器 [转载]

CentOS 5.5下安装mysql5.1.57+php5.2.17(FastCGI)+nginx1.0.1高性能Web服务器 [转载] 2012年09月05日 ⁄ Linux技术 ⁄ 共 12362字 ⁄ 字号 小 中 大 ⁄ 暂无评论 ⁄ 阅读 85 views 次 由于生产环境都是freebsd平台,之前也写了一篇FreeBSD下安装 mysql5.1.56+php5.2.17(FastCGI)+nginx1.0.1高性能Web服务器,有童鞋想要帮忙写一篇关于centos下的安 装教程,其

CentOS 6.8 下安装mysql-5.6

CentOS 6.8 下安装mysql-5.6 安装环境: CentOS release 6.8 (Final) percona-server-5.6.29-76.2 安装依赖库和工具 yum -y install gcc gcc-c++ libgcrypt openssl openssl098e openssl-devel ncurses ncurses-devel make cmake g++ bison ncurses-libs libaio unzip readline-devel yu

怎样在CentOS linux下安装MPEG-1 Layer 3 (MP3)解码器

怎样在CENTOS linux下安装MPEG-1 Layer 3 (MP3)解码器 提片上的信息显示我们没有安装解码器,这是因为版权问题软件 没有自带解码器 我的是centos 32位系统所以用下面第一个源 32位系统 第三方源 rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm 64位系统 第三方源 rpm -ivh http://pkgs.repoforge.

Linux下安装mysql5.6.11(找点有用的信息太费劲)(转)

Linux下安装mysql5.6.11(找点有用的信息太费劲) (2013-04-25 10:25:09)     1.申请阿里云Linux服务器 昨天在阿里云申请了一个免费试用5天的Linux云服务器. 操作系统:Red Hat Enterprise Linux Server 5.4 64位. CPU:1核 内存:512M 硬盘空间:20G 带宽:1Mbps. 今天在这台云服务器上安装了基本环境(JDK.Tomcat和MySQL).本文主要在阿里云Linux云服务器安装MySQL全过程,以及对