快速手動安裝 msyql

FLaravel發表於2019-04-29

記錄一下 centos msyql安裝步驟

  • 下載msyql

    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
  • 解壓

    tar -zxvf  mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
  • 重新命名以及移到合適目錄

    mv mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz  msyql
    mv mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz  /usr/local/
  • 新增使用者和組

    groupadd mysql
    useradd -g mysql mysql
  • 進入/usr/local/msyql目錄,並設定檔案到所屬者

    chown -R mysql:mysql ./
  • 初始化,並記住初始密碼

    /usr/local/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
  • 用systemctl 代替 service

    [Unit]
    Description=MySQL Server
    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
    PIDFile=/usr/local/mysql/data/mysqld.pid
    # Disable service start and stop timeout logic of systemd for mysqld service.
    TimeoutSec=0
    PermissionsStartOnly=true
    # Start main service
    ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/data/mysqld.pid
    # Sets open_files_limit
    LimitNOFILE = 5000
    Restart=on-failure
    RestartPreventExitStatus=1
    PrivateTmp=false
  • 設定開啟啟動並啟動mysql

    systemctl enable msyql
    systemctl statr msyql
  • 大功高成
    msyql

  • 如果不小心忘記密碼

    systemctl stop mysql.service
    /usr/local/mysql/bin/mysqld_safe --skip-grant-tables & 
  • 然後開啟另一個視窗執行下面,即可進入修改密碼

    msyql --uroot -p
    //修改
    update mysql.user set authentication_string=password('新的密碼') where user='root' and Host = 'localhost';
     flush privileges;

關閉 【-- 如何不小心忘記密碼】操作,重新啟動即可

快速手動安裝 msyql

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章