1. 程式人生 > >RedHat編譯安裝MySQL

RedHat編譯安裝MySQL

--------------------

1、下載mysql源碼壓縮包,以及cmake的rpm包:
boost_1_59_0.tar.gz
mysql-5.7.19.tar.gz
cmake-2.8.12.2-4.el6.x86_64.rpm
2、解壓壓縮包,並移動到相應的位置(不固定):
cp -rf boost_1_59_0 /usr/local/boost
cp -rf mysql-5.7.19 /usr/local/mysql
3、創建用戶和組:
groupadd mysql
useradd -g mysql mysql
4、安裝編譯環境依賴包(配置好yum,並掛載):
yum install gcc gcc-c++ -y
yum install -y ncurses-devel.x86_64
yum install -y cmake.x86_64
yum install -y libaio.x86_64
yum install -y bison.x86_64
yum install -y gcc-c++.x86_64
5、安裝cmake:
yum -y localinstall cmake-2.8.12.2-4.el6.x86_64.rpm
6、創建目錄:
mkdir -p /home/mysql3306/mysql3306
mkdir -p /home/mysql3306/logs
給目錄賦權限:
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /home/mysql3306
7、在MySQL安裝目錄進行編譯安裝:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql3306/mysql3306 -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DSYSCONFDIR=/etc -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_BOOST=/usr/local/boost
8、完成之後執行:make && make install
9、將mysql.server加入到服務 (因人而異,不是必須的):
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
10、配置MySQL的配置文件my.cnf(此處配置文件過於簡單,可以根據 需要進行增加):
#vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /home/mysql3306/mysql3306
port = 3306
#character utf8
character_set_server=utf8
init_connect=‘SET NAMES utf8‘
[client]
default-character-set=utf8
socket=/tmp/mysql.sock
11、對MySQL進行初始化(5.7版本 註意初始化的命令):
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --basedir=/usr/local/mysql --datadir=/home/mysql3306/mysql3306/ --user=mysql
12、啟動MySQL服務:service mysqld start
13、進入MySQL初始化權限,給root修改密碼。因為初始化時加入了--initialize-insecure參數可以免密登陸,不加的話會在error log中生成默認密碼。

RedHat編譯安裝MySQL