CentOS7編譯安裝MySQL5.7.24
阿新 • • 發佈:2018-12-06
目錄
安裝依賴
(1)cmake是新版MySQL的編譯工具
sudo yum install gcc gcc-c++ pcre pcre-devel openssl openssl-devel sudo yum install zlib zlib-devel cmake ncurses ncurses-devel bison bison-devel 如下的幾個依賴在CentOS7中需要安裝,CentOS6不需要 sudo yum install perl perl-devel autoconf
安裝boost
如果安裝的MySQL5.7及以上的版本,在編譯安裝之前需要安裝boost,因為高版本mysql需要boots庫的安裝才可以正常執行。否則會報CMake Error at cmake/boost.cmake:81
錯誤
切換到
/usr/local
目錄,然後在這個目錄下下載boost
MySQL5.7.24要求boost的版本是1.59,更高版本的不適用MySQL5.7.24wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
解壓並改名
tar zxvf boost_1_59_0.tar.gz mv boost_1_59_0 boost
在預編譯安裝MySQL時要加上
-DWITH_BOOST=/usr/local/boost
編譯安裝MySQL
# 新增MySQL使用者 useradd -s /sbin/nologin -M mysql # 下載MySQL wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24.tar.gz # 解壓MySQL tar zxvf mysql-5.7.24.tar.gz # 進到MySQL目錄 cd mysql-5.7.24 # 預編譯 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.24 \ -DWITH_BOOST=/usr/local/boost \ -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.7.24/tmp/mysql.sock \ -DMYSQL_DATADIR=/usr/local/mysql-5.7.24/data \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DWITH_INNODB_MEMCACHED=1 \ -DWITH_DEBUG=OFF \ -DWITH_ZLIB=bundled \ -DENABLED_LOCAL_INFILE=1 \ -DENABLED_PROFILING=ON \ -DMYSQL_MAINTAINER_MODE=OFF \ -DMYSQL_TCP_PORT=3306 # 編譯&安裝 make && make install
配置
# 建立軟連線
cd /usr/local
ln -s mysql-5.7.24 mysql
# 新增到環境變數
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
source /etc/profile
cd /usr/local/mysql-5.7.24
mkdir -p /usr/local/mysql-5.7.24/{data,tmp,logs,pids}
chown mysql.mysql /usr/local/mysql-5.7.24/data
chown mysql.mysql /usr/local/mysql-5.7.24/tmp
chown mysql.mysql /usr/local/mysql-5.7.24/logs
chown mysql.mysql /usr/local/mysql-5.7.24/pids
# 修改/etc/my.cnf檔案,編輯配置檔案如下
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/tmp/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/logs/mysqld.log
pid-file=/usr/local/mysql/pids/mysqld.pid
[client]
default-character-set=utf8mb4
# 建立mysqld.log 和 mysqld.pid檔案
touch /usr/local/mysql/logs/mysqld.log
touch /usr/local/mysql/pids/mysqld.pid
# 加入守護程序
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
# 修改MySQL許可權
chown mysql.mysql -R /usr/local/mysql/
# 初始化資料庫, –initialize 表示預設生成一個安全的密碼,–initialize-insecure 表示不生成密碼
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 啟動MySQL
service mysqld start
這裡給一張/etc/my.cnf
的配置圖示
登入MySQL,修改密碼
mysql -u root -p #第一次登陸不需要密碼,回車即可
set password for [email protected] = password('root'); #修改密碼