CentOS7.5中安装MySql(实践踩坑版)

前言

接上篇,SpringBoot从入门到熟悉(二)web开发,在学习springBoot过程中用到了MySql,所以这篇就记录一下我安装MySql的详细过程。因为我是在配置过程中记录在有道云笔记的,所以这篇主要就是复制粘贴我的云笔记了。所以,你还会看到一个前言,GGG

一、前言

最近学习SpringBoot测试中需要MySql,索性就直接往之前租的腾讯云服务器上安装了,搜了一下,网上的教程一般都是基于CentOS 6.0-6.5的 ,CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。今天就快速在CentOS7.5 安装一个Mysql,所以此篇文档最核心的就是快、快、快了

系统环境:腾讯云CentOS 7.5

[root@VM_0_13_centos ~]# cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)

二、安装步骤

第一种方法:

1.更新yum包

yum update

2.查看是否已有老版本Mysql

 先查看机器是否存在安装包、是否已经安装的服务,如果有,则删除或卸载 

rpm -qa|grep -i mysql

结果我的啥都没有,美滋滋:

 

没有其他提示就是没有安装Mysql,如果有,这时候就需要卸载了,卸载步骤大概如下:

博客园:https://www.cnblogs.com/tangkai/p/4172922.html

CSDN:https://blog.csdn.net/huaicainiao/article/details/79185037

3.官网下载安装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

4.安装成功后重启mysql服务。

# service mysqld restart

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

[root@VM_0_13_centos ~]# service mysqld restart

Redirecting to /bin/systemctl restart mysqld.service

[root@VM_0_13_centos ~]# mysql -u root

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

Your MySQL connection id is 2

Server version: 5.6.41 MySQL Community Server (GPL)

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

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

3 rows in set (0.00 sec)



mysql>

 

6.设置密码

参考:

https://www.cnblogs.com/yang82/p/7794712.html

 

 

set password for 'root'@'localhost' =password('123456');

 

修改成功状态:

 

不需要重启数据库即可生效。

在mysql安装过程中有如下内容:

Installed:

mysql-community-client.x86_64 0:5.6.26-2.el7 mysql-community-devel.x86_64 0:5.6.26-2.el7

mysql-community-libs.x86_64 0:5.6.26-2.el7 mysql-community-server.x86_64 0:5.6.26-2.el7



Dependency Installed:

mysql-community-common.x86_64 0:5.6.26-2.el7



Replaced:

mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0

mariadb-server.x86_64 1:5.5.41-2.el7_0

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

[root@VM_0_13_centos ~]# rpm -qa |grep mariadb

[root@VM_0_13_centos ~]#

三、配置Mysql

1.编码

mysql配置文件为/etc/my.cnf

最后加上编码配置

[mysql] 
default-character-set =utf8

2.远程链接设置

把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

mysql> grant all privileges on *.* to root@'%'identified by 'password';

如果是新用户而不是root,则要先新建用户

mysql>create user 'username'@'%' identified by 'password';

此时就可以进行远程连接了。

第二种方法:

安装mariadb

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

安装mariadb,大小59 M。

[root@yl-web yl]# yum install mariadb-server mariadb

 

mariadb数据库的相关命令是:

systemctl start mariadb  #启动MariaDB

systemctl stop mariadb  #停止MariaDB

systemctl restart mariadb  #重启MariaDB

systemctl enable mariadb  #设置开机启动

所以先启动数据库

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

然后就可以正常使用mysql了

[root@yl-web yl]# mysql -u root -p 
Enter password: Welcome to the MariaDB monitor.
 Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.41-MariaDB MariaDB Server Copyright (c) 2000, 2014, 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.00 sec) MariaDB [(none)]>

安装mariadb后显示的也是 MariaDB [(none)]> ,可能看起来有点不习惯,所以自己看着办吧

最后,插入数据后,发现中文数据还是没有正确显示,再修改一遍字符集,如下

修改mysql字符集:

http://www.cnblogs.com/dadadechengzi/p/6034212.html

https://www.cnblogs.com/AloneSword/archive/2013/03/26/2981804.html

修改字符集之后的中文数据:

附上可视化工具navicat破解版:

https://pan.baidu.com/s/1nvIIOad

用户名随意,有下在面的KEY就可以了

NAVN-LNXG-XHHX-5NOO(亲测可行)

 

附录几个安装参考:

csdn:阿里云Cent OS安装MySQL :https://blog.csdn.net/huaicainiao/article/details/79185037

博客园:Cent OS安装My Sql :https://www.cnblogs.com/tangkai/p/4172922.html

博客园:centos7 mysql数据库安装和配置:https://www.cnblogs.com/starof/p/4680083.html

博客园:Centos7安装并配置mysql5.6完美教程https://www.cnblogs.com/lunatic-cto/p/6123490.html

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值