安裝編譯工具和cmake和bison
[root@db mysql-5.5.22]# yum install gcc gcc-c++ ncurses-devel cmake bison
編譯安裝MySQL
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
cd /tmp
tar xvf mysql-5.5.22.tar.gz
mkdir -p /usr/local/mysql #基本目錄
mkdir -p /var/mysql/data #資料目錄
cd mysql-5.5.22/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_DATADIR=/var/mysql/data -DMYSQL_USER=mysql
make
make install
詳細編譯參數參考:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html
一些相關設定
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
mkdir -p /var/mysql/
mkdir -p /var/mysql/data/
mkdir -p /var/mysql/log/
chown -R mysql:mysql /var/mysql/
cd support-files/
cp my-large.cnf /var/mysql/my.cnf
cp mysql.server /etc/rc.d/init.d/mysqld
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/var/mysql/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql
chmod +x /etc/init.d/mysqld
vi /etc/init.d/mysqld(編輯此檔案,尋找並修改以下變數內容:)
basedir=/usr/local/mysql
datadir=/var/mysql/data
加入啟動項:
chkconfig --add mysqld
chkconfig --level 345 mysqld on
啟動服務:
service mysqld start
vi /etc/profile 添加
export PATH=$PATH:/usr/local/mysql/bin
mysql>
設定密碼
mysql -uroot -p