阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS7.2下安装MySQL

181次阅读
没有评论

共计 2704 个字符,预计需要花费 7 分钟才能阅读完成。

一、系统环境

 [root@localhost home]# cat /etc/RedHat-release

 CentOS Linux release 7.2.1511 (Core)

二、mysql 安装

 安装 mysql 和 mysql-devel 都成功,但是安装 mysql-server 失败,如下:

[root@localhost home]# yum install mysql-server
    已加载插件:fastestmirror, langpacks
    Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
    base                                                                    | 3.6 kB  00:00:00     
    extras                                                                  | 3.4 kB  00:00:00     
    updates                                                                 | 3.4 kB  00:00:00     
   (1/4): base/7/x86_64/group_gz                                           | 155 kB  00:00:01     
   (2/4): extras/7/x86_64/primary_db                                       | 139 kB  00:00:01     
   (3/4): base/7/x86_64/primary_db                                         | 5.6 MB  00:00:38     
   (4/4): updates/7/x86_64/primary_db                                      | 4.7 MB  00:00:39     
 Loading mirror speeds from cached hostfile
  * base: mirrors.163.com
  * extras: mirrors.163.com
  * updates: mirrors.163.com
 没有可用软件包 mysql-server。错误:无须任何处理 

出现这样问题是 CentOS 7 版本将 MySQL 数据库软件从默认的程序列表中移除,用 mariadb 代替了

有两种解决办法:

 1、方法一:安装 mariadb

MariaDB 数据库管理系统是 MySQL 的一个分支,采用 GPL 授权许可 MariaDB 的目的是完全兼容 MySQL,包括 API 和命令行,使之能轻松成为 MySQL 的代替品。MariaDB 由 MySQL 的创始人 Michael Widenius(英语:Michael Widenius)主导开发,他早前将自己创建的公司 MySQL AB 卖给了 SUN,此后,随着 SUN 被甲骨文收购,MySQL 的所有权也落入 Oracle 的手中。MariaDB 名称来自 Michael Widenius 的女儿 Maria 的名字。

安装 mariadb,输入安装命令

[root@localhost home]# yum install mariadb-server mariadb

CentOS7.2 下安装 MySQL

mariadb 数据库的相关命令是:

   systemctl start mariadb  #启动 MariaDB

   systemctl stop mariadb  #停止 MariaDB

   systemctl restart mariadb  #重启 MariaDB

   systemctl enable mariadb  #设置开机启动

先启动数据库

  [root@yl-web yl]# systemctl start mariadb

  默认无密码

[root@localhost lzh]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

2、方法二:官网下载安装 mysql-server

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

安装成功后重启 mysql 服务

    # service mysqld restart

初次安装 mysql,root 账户没有密码

[root@localhost lzh]# mysql -u root 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

设置密码

mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)

安装完以后 mariadb 自动就被替换了,将不再生效。

[root@localhost lzh]# rpm -qa |grep mariadb

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-04/142863.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计2704字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中