【轉】centos7.9源碼安裝mysql5.7.44

原文:https://blog.csdn.net/SeeYouGoodBye/article/details/135231451

1、環境介紹

  • centos7.9
  • mysql5.7.44
  • boost1.59.0

注意:這裏的編譯版本mysql5.7.44和boost1.59.0是有依賴的,建議使用相同版本

2、安裝編譯要用的依賴軟件

yum install -y  gcc gcc-c++ cmake libaio-devel ncurses ncurses-devel bison openssl-devel

3、準備編譯的源碼包

mysql源碼包下載:

boost源碼包下載:

img

img

注意:國內下載這個boost包很慢

#可直接linux上用wget下載



wget https://zenlayer.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz



 



wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.44.tar.gz

4、創建mysql用戶

groupadd mysql



useradd -r -g mysql -M -s /sbin/nologin mysql

5、創建數據庫目錄(此目錄可自定義)

mkdir -p /opt/mysql



chown mysql:mysql /opt/mysql



 



#目錄自定義後,後面配置文件路徑相應要改變

6、編譯安裝mysql和boost

#將本地下載的2個源碼包傳至/root



cd /root/



 



tar -xf boost_1_59_0.tar.gz



mv boost_1_59_0 /usr/local/boost



 



tar -xf mysql-5.7.44.tar.gz -C /usr/local/src/



cd /usr/local/src/mysql-5.7.44



cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/opt/mysql  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/opt/mysql/mysql.sock  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1    -DDOWNLOAD_BOOST=0 -DWITH_BOOST=../../boost -DWITH_INNODB_MEMCACHED=ON



 



make



make install

7、編輯my.cnf並初始化mysql數據庫

#先備份編譯安裝後自動生成的



mv /etc/my.cnf /etc/my.cnf.bak



 



#自定義my.cnf



cat >/etc/my.cnf<<EOF



[client]



port=3306



socket=/opt/mysql/mysql.sock







[mysqld]



character-set-server=utf8



collation-server=utf8_general_ci







skip-name-resolve



user=mysql



port=3306



basedir=/usr/local/mysql



datadir=/opt/mysql



tmpdir=/tmp



socket=/opt/mysql/mysql.sock







log-error=/opt/mysql/mysqld.log



pid-file=/opt/mysql/mysqld.pid 



EOF



 



 



#根據my.cnf初始化mysql



/usr/local/mysql/bin/mysqld  --defaults-file=/etc/my.cnf   --initialize  --user=mysql



 



 



#開啓數據庫並查看狀態



/usr/local/mysql/support-files/mysql.server start



 



/usr/local/mysql/support-files/mysql.server status



 



 



#查看登錄root的初始密碼



cat /opt/mysql/mysqld.log | grep root

8、設置mysql環境變量

vi /etc/profile



...



export MYSQL_HOME=/usr/local/mysql



export PATH=$PATH:$MYSQL_HOME/bin



 



 



source /etc/profile

9、修改root的初始密碼

#這裏用前面查到的初始密碼登錄



mysql -uroot -p



Enter password: 



Welcome to the MySQL monitor.  Commands end with ; or \g.



Your MySQL connection id is 2



Server version: 5.7.44



 



Copyright (c) 2000, 2023, Oracle and/or its affiliates.



 



Oracle is a registered trademark of Oracle Corporation and/or its



affiliates. Other names may be trademarks of their respective



owners.



 



Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



 



mysql> 



mysql> alter user root@localhost identified by 'ziu1988Q...'



    -> ;



Query OK, 0 rows affected (0.00 sec)



 



mysql> flush privileges;



Query OK, 0 rows affected (0.00 sec)



 



 



#關閉數據庫服務(爲了後面設置的自啓正常使用)



/usr/local/mysql/support-files/mysql.server stop

10、設置啓動文件以及開機自啓

#複製啓動文件到常用啓動目錄



cp /usr/local/mysql/support-files/mysql.server /etc/init.d/



 



#編輯啓動service



vi /usr/lib/systemd/system/mysql.service



[Unit]



Description=MySQL Community Server



After=network.target



 



[Install]



WantedBy=multi-user.target



 



[Service]



User=mysql



Group=mysql



Type=forking



PermissionsStartOnly=true



PIDFile=/opt/mysql/mysqld.pid



ExecStartPre=/etc/init.d/mysql.server restart



ExecStart=/etc/init.d/mysql.server start



TimeoutSec=600



LimitNOFILE = 5000



Restart=on-failure



RestartPreventExitStatus=1



RuntimeDirectory=mysqld



RuntimeDirectoryMode=755



 



 



#重載配置和啓動mysql,設置開機自啓



systemctl daemon-reload



systemctl start mysql



systemctl enable mysql

文章知識點與官方知識檔案匹配,可進一步學習相關知識

雲原生入門技能樹首頁概覽18569 人正在系統學習中

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章