CentOS之Mysql 5.5 安装-yellowcong

19 篇文章 0 订阅

CentOS的安装,需要安装mysql,mysql-devel和 mysql-server(这个有点问题,主要是CentOS仓库没有mysql-server,但是有个替代品mariadb ),我是通过直接下载官方的安装文件,然后再重启服务,设定编码和用户的密码。

Mysql安装

一般安装Mysql,需要安装这三个组件,但是我淡疼的遇到了yum install mysql-server这个安装不上

yum install -y mysql mysql-devel mysql-server

mysql-server 安装失败

CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。MariaDB可以说是Mysql的替代品,应为Mysql被甲骨文公司收购了,怕那一天不公开了,所以有MariaDB的产生,他是Mysql的一个分支,可以支持Mysql的API和命令

[root@localhost ~]# yum install mysql-server
已加载插件:fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
没有可用软件包 mysql-server。
错误:无须任何处理

官网下载安装mysql-server

我们不能直接安装Mysql-server,但是我们可以从官网上 下载安装包,然后进行安装

#镜像地址信息 mysql-5.7-x86_64 mysql版本信息
#https://centos.pkgs.org/7/mysql-5.7-x86_64/
#mysql 5.7 文档
#https://blog.csdn.net/xyang81/article/details/51759200 

#查询已经安装的mysql ,如果安装了,可以 yum autoremove -y xx 卸载
yum list installed | grep mysql

#5.7版本
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
#安装mysql
yum install mysql-community-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重启

安装完成后,重启mysql服务service mysql restart

[root@localhost ~]# service mysql restart
Redirecting to /bin/systemctl restart  mysql.service

mysql登录

登录Mysqlmysql -u root,第一次登录不需要输入密码


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

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

配置mysql

设置Mysql密码

执行命令set password for ‘root’@‘localhost’ = password(‘root’);,就可以设定root用户的密码为 root

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

设置编码

设置编码为UTF8

[mysql]
default-character-set =utf8

这里写图片描述

/usr/share/mysql/charsets/Index.xml中有一堆编码,我们的编码要里面存在,不然瞎配置,就JJ了,我们一般用的是gbk和utf8两个编码

<charset name="gbk">
  <family>East Asian</family>
  <description>GBK Simplified Chinese</description>
  <alias>cp936</alias>
  <collation name="gbk_chinese_ci"      id="28" order="Chinese">
    <flag>primary</flag>
    <flag>compiled</flag>
  </collation>
  <collation name="gbk_bin"     id="87" order="Binary">
    <flag>binary</flag>
    <flag>compiled</flag>
  </collation>
</charset>

<charset name="utf8">
  <family>Unicode</family>
  <description>UTF-8 Unicode</description>
  <alias>utf-8</alias>
  <collation name="utf8_general_ci"     id="33">
   <flag>primary</flag>
   <flag>compiled</flag>
  </collation>
  <collation name="utf8_bin"            id="83">
    <flag>binary</flag>
    <flag>compiled</flag>
  </collation>
</charset>

手动设置编码

set character_set_client = utf8;

set character_set_server = utf8;

set character_set_connection = utf8;

set character_set_database = utf8;

set character_set_results = utf8;

set collation_connection = utf8_general_ci;

set collation_database = utf8_general_ci;

set collation_server = utf8_general_ci;

查看编码

show variables like 'char%';

这里写图片描述

创建用户

create user '用户名'@'%' identified by '密码';  

开启远程访问

设定root用户,使用密码root可以远程访问数据库

 GRANT ALL PRIVILEGES ON *.*TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

如果远程连接不上,可能是你的防火墙设置有问题,可以参考我的防火墙设置的文章

iptables -A INPUT -p tcp -m tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT

这里写图片描述

这里写图片描述

设置 开机启动

#设定mysql开启骑启动
chkconfig mysqld on
#取消开机启动操作
chkconfig mysqld off

#查看是否是开机启动
systemctl list-unit-files|grep mysql

#这个也可以查看是否启动,但是在centos7中不支持
chkconfig --list |grep mysql

这里写图片描述

查看结果,chkconfig --list |grep mysql这种方式不一定支持

这里写图片描述

安装mariadb

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

yum install mariadb-server mariadb 

mariadb数据库的相关命令是:

systemctl start mariadb  #启动MariaDB
systemctl stop mariadb  #停止MariaDB
systemctl restart mariadb  #重启MariaDB
systemctl enable mariadb  #设置开机启动
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

狂飙的yellowcong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值