CentOS 6.7下yum方式安装MySQL 5.6

来源:这里教程网 时间:2026-03-01 15:04:01 作者:

1、下载yum源

 我的测试环境如下:

[root@test ~]# cat /etc/redhat-release CentOS release 6.7 (Final)

所以下载了centos6系统yum源:

 

wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm

 

 

3、修改yum源配置

 vim /etc/yum.repos.d/mysql-community.repo

 

安装mysql5.6操作

 

1)、将其他版本enabled=1更改为enabled=0

2)、将5.6版本enabled=0更改为enabled=1

 

 

# Enable to use MySQL 5.6

[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

 

4 、开始现在安装包并安装

[root@test ~]# yum install mysql-community-server

已加载插件: fastestmirror, security

设置安装进程

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * epel: mirrors.yun-idc.com

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

解决依赖关系

--> 执行事务检查

---> Package mysql-community-server.x86_64 0:5.6.47-2.el6 will be 安装

--> 处理依赖关系 mysql-community-common(x86-64) = 5.6.47-2.el6 ,它被软件包 mysql-community-server-5.6.47-2.el6.x86_64 需要

--> 处理依赖关系 mysql-community-client(x86-64) >= 5.6.10 ,它被软件包 mysql-community-server-5.6.47-2.el6.x86_64 需要

--> 执行事务检查

---> Package mysql-community-client.x86_64 0:5.6.47-2.el6 will be 安装

--> 处理依赖关系 mysql-community-libs(x86-64) >= 5.6.10 ,它被软件包 mysql-community-client-5.6.47-2.el6.x86_64 需要

---> Package mysql-community-common.x86_64 0:5.6.47-2.el6 will be 安装

--> 执行事务检查

---> Package mysql-community-libs.x86_64 0:5.6.47-2.el6 will be 安装

--> 完成依赖关系计算

 

依赖关系解决

 

================================================================================================================================================================

  软件包                                         架构                           版本                                 仓库                                       大小

================================================================================================================================================================

正在安装 :

 mysql-community-server                        x86_64                        5.6.47-2.el6                        mysql56-community                         77 M

为依赖而安装 :

 mysql-community-client                        x86_64                        5.6.47-2.el6                        mysql56-community                         34 M

 mysql-community-common                        x86_64                        5.6.47-2.el6                        mysql56-community                        341 k

 mysql-community-libs                          x86_64                        5.6.47-2.el6                        mysql56-community                        3.6 M

 

事务概要

================================================================================================================================================================

Install       4 Package(s)

 

总文件大小: 114 M

总下载量: 77 M

Installed size: 478 M

确定吗? [y/N] y

下载软件包:

mysql-community-server-5.6.47-2.el6.x86_64.rpm                                                                                           |  77 MB     43:30    

warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

Importing GPG key 0x5072E1F5:

 Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>

 Package: mysql57-community-release-el6-7.noarch (installed)

 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

确定吗? [y/N] y

运行 rpm_check_debug

执行事务测试

事务测试成功

执行事务

Warning: RPMDB altered outside of yum.

  正在安装    : mysql-community-common-5.6.47-2.el6.x86_64                                                                                                   1/4

  正在安装    : mysql-community-libs-5.6.47-2.el6.x86_64                                                                                                     2/4

  正在安装    : mysql-community-client-5.6.47-2.el6.x86_64                                                                                                   3/4

  正在安装    : mysql-community-server-5.6.47-2.el6.x86_64                                                                                                   4/4

  Verifying  : mysql-community-libs-5.6.47-2.el6.x86_64                                                                                                     1/4

  Verifying  : mysql-community-common-5.6.47-2.el6.x86_64                                                                                                   2/4

  Verifying  : mysql-community-client-5.6.47-2.el6.x86_64                                                                                                   3/4

  Verifying  : mysql-community-server-5.6.47-2.el6.x86_64                                                                                                   4/4

 

已安装 :

  mysql-community-server.x86_64 0:5.6.47-2.el6                                                                                                                 

 

作为依赖被安装 :

  mysql-community-client.x86_64 0:5.6.47-2.el6         mysql-community-common.x86_64 0:5.6.47-2.el6         mysql-community-libs.x86_64 0:5.6.47-2.el6       

 

完毕!

 

 

5 、启动 mysql 服务

[root@test ~]# service mysqld start

初始化 MySQL 数据库: 2020-03-30 23:47:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-03-30 23:47:20 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

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 test password 'new-password'

 

Alternatively you can run:

 

  /usr/bin/mysql_secure_installation

 

which will also give you the option of removing the test

Note: new default config file not created.

Please make sure your config file is current

 

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server

 

                                                           [ 确定 ]

正在启动 mysqld                                           [ 确定 ]

 

6 、查看状态和版本

[root@test ~]#  chkconfig --list | grep mysqld

mysqld          0: 关闭   1: 关闭   2: 关闭   3: 启用   4: 启用   5: 启用   6: 关闭

[root@test ~]# mysqladmin --version

mysqladmin  Ver 8.42 Distrib 5.6.47, for Linux on x86_64

[root@test ~]#  mysqladmin -u root password "mysql123"

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

[root@test ~]# mysql -u root -p

Enter password:

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

Your MySQL connection id is 3

Server version: 5.6.47 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2020, 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.

 

7 、设置 root 用户密码

[root@test ~]#  mysqladmin -u root password "mysql123"

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

 

 

8 、查看数据库和创建数据库

 

 

[root@test mysql]# mysql -u root -p

Enter password:

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

Your MySQL connection id is 5

Server version: 5.6.47 MySQL Community Server (GPL)

 

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

3 rows in set (0.00 sec)

 

mysql> CREATE DATABASE testtb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

Query OK, 1 row affected (0.00 sec)

 

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| testtb             |

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

4 rows in set (0.00 sec)

 

9 、查看数据库目录

[root@test ~]# ls /var/lib/mysql -al

总用量 110616

drwxr-xr-x   5 mysql mysql     4096 3   31 00:19 .

drwxr-xr-x. 30 root  root      4096 3   30 20:57 ..

-rw-rw----   1 mysql mysql       56 3   30 23:47 auto.cnf

-rw-rw----   1 mysql mysql 12582912 3   30 23:47 ibdata1

-rw-rw----   1 mysql mysql 50331648 3   30 23:47 ib_logfile0

-rw-rw----   1 mysql mysql 50331648 3   30 23:47 ib_logfile1

drwx------   2 mysql mysql     4096 3   30 23:47 mysql

srwxrwxrwx   1 mysql mysql        0 3   30 23:47 mysql.sock

drwx------   2 mysql mysql     4096 3   30 23:47 performance_schema

drwx------   2 mysql mysql     4096 3   31 00:19 testtb

相关推荐