1. 程式人生 > >centos7安裝mysql-5.5.60

centos7安裝mysql-5.5.60

inf -- bug kcon config 卸載centos 連接 collation root

1.安裝之前的準備
  • 卸載centos7自帶的mariadb

    rpm -qa|grep mariadb     #查看一下是否有mariadb相關的包
    rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64      #把查詢到的包卸載
  • 下載mysql安裝包
    wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.60.tar.gz
  • 下載cmake安裝包
    wget https://cmake.org/files/v3.10/cmake-3.10.2.tar.gz
  • 添加mysql用戶和組
    groupadd mysql
    useradd mysql -s /sbin/nologin -M -g mysql   # -s /sbin/nologin 表示禁止該用戶登錄,加強安全; -g mysql 指定屬於mysql組; -M 表示不創建用戶家目錄
  • 安裝ncurses-devel
    yum install ncurses-devel -y
  • 安裝cmake
    tar zxvf cmake-3.10.2.tar.gz -C /usr/local
    cd /usr/local/cmake-3.10.2
    ./configure
    gmake && gmake install

2.安裝myqsl

tar zxvf mysql-5.5.60.tar.gz
cd mysql-5.5.60
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.60 -DMYSQL_DATADIR=/application/mysql-5.5.60/data -DMYSQL_UNIX_ADDR=/application/mysql-5.5.60/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
make && make install
  • 做軟連接

    ln -s /application/mysql-5.5.60/ /application/mysql
  • mysql目錄授權

    chown -R mysql:mysql /application/mysql-5.5.60/
  • 復制相關文件

    cd /application/mysql/support-files
    cp my-small.cnf /etc/my.cnf
    cp mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
  • mysql初始化
    cd /application/mysql/scripts/
    ./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
  • 啟動mysql
    /etc/init.d/mysqld start
  • 配置環境變量
    echo ‘export PATH=/application/mysql/bin:$PATH‘>>/etc/profile
    source /etc/profile
  • 配置登陸密碼
    /application/mysql//bin/mysqladmin -u root password ‘zacs164.com‘
  • 設置mysql開機啟動

    chkconfig mysqld on
    chkconfig --list mysqld        #查看一下
  • 登錄mysql

正常的情況是可以正常登陸進去的,但是我在登錄的時候報了以下錯誤信息:

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

解決方法:

  • 1.停止mysql數據庫
    /etc/init.d/mysqld stop
  • 2.執行如下命令
    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &   
  • 3.使用root登錄mysql數據庫
    mysql -u root mysql
  • 4.更新root密碼
    UPDATE user SET Password=PASSWORD(‘ZACS164.COM‘) where USER=‘root‘;
  • 5.刷新權限
    FLUSH PRIVILEGES;
  • 6.退出mysql
  • 7.重啟mysql

    /etc/init.d/mysqld restart
  • 8.使用root用戶重新登錄mysql

centos7安裝mysql-5.5.60