作為博主這樣的Linux菜鳥,CentOS下最喜歡的就是yum安裝。但有時候因為特殊情況(例如被牆等),某些軟件可能沒辦法直接通過yum來安裝,這時候我們可以使用編譯安裝或者直接二進制文件安裝。
本博文用於記錄編譯安裝MySQL的過程:
1.首先下載相關資源:
| 組件 | 官方網站 | 下載地址 | 備注 |
| mysql | http://dev.mysql.com/ | https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz | mysql源碼 |
| Boost | http://www.boost.org/ | http://120.52.73.44/nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz | 編譯時使用,必須是Boost 1.59.0 |
2.安裝依賴包:
yum install -y gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake libaio libaio-devel autoconf bzr bison libtool
3.解壓並安裝Boost(拷貝至/usr/local/boost目錄)
tar -zxf boost_1_59_0.tar.gz mv /tmp/boost_1_59_0 /usr/local/boost
4.解壓MySQL源瑪
tar -zxf mysql-5.7.19.tar.gz
5.准備MySQL數據,日志等路徑,並創建mysql用戶,賦予mysql用戶相關文件夾權限
mkdir -p /usr/local/mysql /binlog/mysqlog /data/mysql groupadd -r mysql useradd -g mysql -r -d /data/mysql mysql chown -R mysql.mysql /usr/local/mysql /binlog/mysqlog /data/mysql
6.編譯安裝
cd mysql-5.7.19 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DMYSQL_DATADIR=/data/mysql \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DMYSQL_TCP_PORT=3306 \ -DWITH_DEBUG=0 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DSYSCONFDIR=/etc/my.cnf \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_BOOST=/usr/local/boost \
make && make install
7.編輯my.cnf文件
vi /etc/my.cnf
幾個路徑的地方記得修改:
[mysqld] datadir=/data/mysql socket=/tmp/mysql.sock basedir = /usr/local/mysql # basic setting user=mysql port=3306 server-id=11 #log slow_query_log_file = /binlog/mysqlog/slow.log slow_query_log = 1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/binlog/mysqlog/err.log
8.初始化MySQL
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql --socket=/tmp/mysql.sock --log-error=/binlog/mysqlog/err.log --log-bin=/binlog/mysqlog/mysql-bin
9.添加MySQL服務
cd /tmp/mysql-5.7.19/support-files cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
10.啟動MySQL
/etc/init.d/mysql start
11.查看mysql進程
ps -ef | grep mysql
12.建立Mysql映射
ln -s /usr/local/mysql/bin/mysql /usr/bin
13.查找mysql初始密碼
sudo grep 'temporary password' /binlog/mysqlog/err.log
14.初次登錄,修改密碼
mysql -uroot -p
set password=password('newpassword');
打完收工。
