欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql安装配置方法图文教程(CentOS7)

程序员文章站 2023-10-30 18:11:34
一、系统环境  [root@localhost home]# cat /etc/redhat-release  centos linux rel...

一、系统环境

 [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代替了

两种解决办法:

方法一:安装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

mysql安装配置方法图文教程(CentOS7)

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)

方法二:官网下载安装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

精彩专题分享:mysql不同版本安装教程 mysql5.7各版本安装教程 mysql5.6各版本安装教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。