暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

mysqld.service

郭靖师傅看我的眼色行事 2021-10-13
1758

/usr/lib/systemd/system/mysqld.service

chmod 644 mysqld.service

    [unit]
    Description=MySQL Server
    Documentation=man:mysqld[7]
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    User=mysql
    Group=mysql
    Type=forking
    PIDFile=/data/mysql/node.pid
    TimeoutSec=0
    ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize --pid-file=/data/mysql/node.pid $MYSQLD_OPTS
    EnvironmentFile=-/etc/sysconfig/mysql
    #sets open_files_limit
    LimitNOFILE=65536
    Restart=on-failure
    RestartPreventExitStatus=1
    PrivateTmp=false


      cd /usr/lib/tmpfiles.d
      cat /usr/lib/tmpfiles.d/mysql.conf
      d /data/mysql 0750 mysql mysql -
      chmod 644 mysql.conf
      systemctl enable mysqld.service
      systemctl start mysqld
      systemctl 日志
      journalctl -u mysqld
      systemctl daemon-reload
      systemctl restart mysqld


        systemctl set-environment MYSQLD_OPTS="--general_log=0"
        systemctl restart mysqld

        上面启动方式会覆盖my.cnf配置

        systemctl unset-environment MYSQLD_OPTS

        还可以直接编辑/etc/sysconfig/mysql文件



        1.关闭防火墙

          systemctl status firewalld|grep -i "Active:"
          systemctl stop firewalld
          systemctl disable firewalld


          2.禁用SELINUX策略,重启后生效

            cat etc/selinux/config|egrep -i "SELINUX=e|SELINUX=p|SELINUX=d" 
            SELINUX=enforcing
            sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' etc/selinux/config

            setenforce 0 临时生效

            3.检查系统时间和时区

            date +"%Y-%m-%d %H:%M:%S"

            timedatectl|grep -i "Time zone"

            4设置mysql系统账户资源限制

              cat /etc/security/limits.conf
              mysql soft nproc 2047
              mysql hard nproc 16384
              mysql soft nofile 1024
              mysql hard nofile 65536


              2)动态生效资源限制

                ulimit -Sn 1024
                ulimit -Hn 65536
                ulimit -Su 2047
                ulimit -Hu 16384


                3)检查资源生效情况

                  ulimit -a -S|egrep -i "open files|max user processes"
                  ulimit -a -H|egrep -i "open files|max user processes"

                  检查内核资源限制

                  4)

                    sysctl -a|egrep -w "fs.file-max|kernel.pid_max"


                    sysctl -p

                    5.卸载与mysql互斥的依赖包

                    rpm -qa|egrep -i "mysql|maridb"

                    rpm -ql 包名

                    rpm -e    卸载

                    如果出现依赖错误,可以加--nodeps


                      groupadd mysql
                      useradd -r -g mysql -s bin/false mysql
                      mkdir -p mysql/app
                      mkdir -p mysql/product/{data,log,binlog,relaylog,redo,unod,mysql-files}
                      chown -R mysql:mysql mysql
                      chmod -R 750 /mysql
                      tar zxvf mysql-...tar.gz -C /mysql/app --strip-components=1




                      echo 'export PATH=/mysql/app/bin:$PATH'>> $HOME/.bash_profile
                      source $HOME/.bash_profile




                      mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
                      cat /mysql/product/log/mysql.err|grep -i "A temporary password"


                      MYSQL8.0中,mysqld_safe 启动守护进程的方式已经过期,并逐渐废弃(与采用的安装方式有关),用户可以使用systemd方式替代

                      5.7

                        update mysql.user set authentication_string=password('root') where user='root' and host='localhost';

                        8.0  修改密码建议先置空,在使用alter 命令

                          alter user 'root'@'localhost' identified by 'root';
                          update mysql.user set authentication_string='' where user='root' and host='localhost';
                          flush privileges;


                          文章转载自郭靖师傅看我的眼色行事,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                          评论