Centos7 安装和配置MySQL5.7

Centos7 安装和配置MySQL5.7

第一步,下载MySQL安装


 
 
  1. [root@localhost ~] # cd /home/data/
  2. [root@localhost 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. [root@localhost data] # wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

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

yum -y install wget
 
 

下载完成后

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

安装mysql安装源

[root@localhost data]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 

 
 

第二步,在线安装MySQL

[root@localhost data]# yum -y install mysql-community-server
 
 

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

第三步,启动MySQL服务

[root@localhost data]# systemctl start mysqld

 
 

第四步,设置开机启动


 
 
  1. [root@localhost data] # systemctl enable mysqld
  2. [root@localhost data] # systemctl daemon-reload

第五步,修改root登录密码

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

[root@localhost data]# vim /var/log/mysqld.log
 
 

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


 
 
  1. [root@localhost 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 'Test2016@';
  2. Query OK, 0 rows affected (0.01 sec)

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


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

第七步,退出


 
 
  1. mysql> exit
  2. Bye

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


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

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

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

character_set_server=utf8

init_connect='SET NAMES utf8'

:wq!保存退出

第十步,重启MySQL

[root@localhost data]# systemctl restart mysqld

 
 

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

第十二步,测试远程连接

 

 

 

 

 

 

 

 

  •                     <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>
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值