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

Centos7 安装和配置MySQL5.7

程序员文章站 2022-05-08 10:58:33
...

Centos7 安装和配置MySQL5.7

第一步,下载MySQL安装

  1. [aaa@qq.com ~]# cd /home/data/
  2. [aaa@qq.com data]# ls
  3. get-docker.sh nginx-1.10.1 nginx-1.10.1.tar.gz redis-5.0.3 redis-5.0.3.tar.gz server-jre-8u131-linux-x64.tar.gz zookeeper-3.4.10.tar.gz
  4. [aaa@qq.com data]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

如果提示wget命令不存在,先执行

yum -y install wget

下载完成后

Centos7 安装和配置MySQL5.7

多了一个mysql57-xxx的文件,这个就是mysql安装源

安装mysql安装源

[aaa@qq.com data]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 

第二步,在线安装MySQL

[aaa@qq.com data]# yum -y install mysql-community-server

下载的东西有点多,需要等待一会

第三步,启动MySQL服务

[aaa@qq.com data]# systemctl start mysqld

第四步,设置开机启动

  1. [aaa@qq.com data]# systemctl enable mysqld
  2. [aaa@qq.com data]# systemctl daemon-reload

第五步,修改root登录密码

mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。

[aaa@qq.com data]# vim /var/log/mysqld.log

Centos7 安装和配置MySQL5.7

复制此密码,使用此密码登录root

  1. [aaa@qq.com data]# mysql -u root -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.7.25
  6. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql>

修改密码, mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位

  1. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'aaa@qq.com';
  2. Query OK, 0 rows affected (0.01 sec)

第六步,设置允许远程登录

  1. mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'aaa@qq.com' WITH GRANT OPTION;
  2. Query OK, 0 rows affected, 1 warning (0.00 sec)

第七步,退出

  1. mysql> exit
  2. Bye

第八步,防火墙开放3306端口

  1. [aaa@qq.com data]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
  2. success
  3. [aaa@qq.com data]# firewall-cmd --reload
  4. success
  5. [aaa@qq.com data]#

第九步,配置mysql默认编码为utf-8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置

character_set_server=utf8

init_connect='SET NAMES utf8'

Centos7 安装和配置MySQL5.7

:wq!保存退出

第十步,重启MySQL

[aaa@qq.com data]# systemctl restart mysqld

第十一步,登录root用户查看编码

Centos7 安装和配置MySQL5.7

第十二步,测试远程连接

Centos7 安装和配置MySQL5.7

Centos7 安装和配置MySQL5.7

 

 

 

 

 

 

 

 

                        <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count">5</span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/WYA1993">
                    <img src="https://profile.csdnimg.cn/6/F/2/3_wya1993" class="avatar_pic" username="WYA1993">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/1x/4.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/WYA1993" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">myCat、</a></span>
                                            </div>
                    <div class="text"><span>发布了141 篇原创文章</span> · <span>获赞 88</span> · <span>访问量 17万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=WYA1993" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
                    </div>
    </article>
    
    相关标签: java Centos7