• centos下mysql配置


    centos7下安装mysql(完整配置)

    1. 下载并安装MySQL官方的Yum Repository

    [root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    
    • 1

    使用上面的命令直接安装Yum Repository

    [root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
    
    • 1

    安装MySQL服务器

    root@localhost ~]# yum -y install mysql-community-server
    
    • 1

    2. MySQL数据库设置
    启动MySQL

    [root@localhost ~]# systemctl start  mysqld.service
    
    • 1

    查看MySQL运行状态

    [root@localhost ~]# systemctl status mysqld.service
    
    • 1

    此时MySQL已经开始正常运行,需要找出root的密码

    [root@localhost ~]# grep "password" /var/log/mysqld.log
    
    • 1

    如下命令登录mysql

    # mysql -uroot -p
    
    • 1

    输入初始密码,此时不能做任何事情,因为MYSQL默认必须修改密码才能正常使用

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
    

    这里会遇到一个问题,新密码设置过于简单会报错

    • 1
    • 2
    • 3

    可通过如下命令查看完整的初始密码规则

    mysql>show variables like 'validate_password';
    
    • 1

    可通过如下命令修改

    mysql> set global validate_password_policy=0;
    mysql> set global validate_password_length=1;
    
    • 1
    • 2

    还有一个问题就是Yum Repository,以后每次 yum 操作都会自动更新,需要把这个卸载掉

    [root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
    
    • 1

    远程登录数据库出现下面出错信息
    ERROR 2003 (HY000): Can’t connect to MySQL server on ‘xxx.xxx.xxx.xxx’,
    原因是没有授予相应的权限

    #任何主机
    mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    

    指定主机

    mysql>GRANT ALL PRIVILEGES ON . TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;

    然后刷新权限

    mysql>flush privileges;

    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    修改mysql数据库总的user表使相的用户能从某一主机登录

    mysql>use mysql;
    mysql>update user set host = '%' where user = 'root';
    mysql>select host, user from user;
    
    • 1
    • 2
    • 3

    客户端提供MYSQL的环境,但是不支持中文,通过以下命令可以查看mysql的字符集

    mysql>show variables like 'character_set%';
    
    • 1

    显示如下:

    image

    为了让 MySQL支持中文,需要把字符集改成UTF-8,方法如下

    # vim /etc/my.cnf
    
    • 1

    改成如下内容

    [client]
    port=3306
    socket=/var/lib/mysql/mysql.sock
    default-character-set=utf8
    

    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    user=mysql

    Disabling symbolic-links is recommended to prevent assorted security risks

    symbolic-links=0
    character-set-server=utf8

    [mysql]
    no-auto-rehash
    default-character-set=utf8

    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid

    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    重启mysql服务

    # service mysqld restart
    
    • 1

    重新查看数据库编码

    show variables like 'character_set%';
    
    • 1

    效果如下,可看到都改为utf-8

    image

                                    </div>
                <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
                                                <div class="more-toolbox">
                <div class="left-toolbox">
                    <ul class="toolbox-list">
                        
                        <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">22</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:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;}"><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/baidu_32872293">
                    <img src="https://profile.csdnimg.cn/8/C/B/3_baidu_32872293" class="avatar_pic" username="baidu_32872293">
                                            <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/baidu_32872293" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">zengrui_0337</a></span>
                                            </div>
                    <div class="text"><span>发布了27 篇原创文章</span> · <span>获赞 29</span> · <span>访问量 5万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=baidu_32872293" 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>
    
  • 相关阅读:
    Alibaba 阿里组件 nacos注册中心 gateway网关 flowable流程引擎 vue.js前后分离 spring cloud微服务
    Java JDBC 连接 MySQL8 数据库
    Java设计模式【命令模式】
    Spring Boot内嵌tomcat关于getServletContext().getRealPath获取得到临时路径的问题
    Java代理模式学习 (Proxy模式)
    Java单例模式浅析 (Singleton模式)
    由歌词引发的模式思考之中篇(AbstractFactory模式)
    Java模拟FilterChain的实现 (Chain Of Responsibility模式)
    由歌词引发的模式思考之上篇(FactoryMethod模式)
    由歌词引发的模式思考之下篇(模拟Spring的BeanFactory)
  • 原文地址:https://www.cnblogs.com/python001-vip/p/12457282.html
Copyright © 2020-2023  润新知