程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> 02-mysql-安裝

02-mysql-安裝

編輯:MySQL綜合教程

02-mysql-安裝


02-mysql-安裝
----MySQL安裝版本以及技術文檔
mysql目前常用版本 mysql-5.6.15.tar.gz


----MySQL編譯安裝
1. 安裝環境要求:mysql用戶和組且ID為27,安裝軟件make,cmake,gcc,gcc-c++,ncurses-devel ,bison。 groupadd -g 27 mysql useradd -u 27 -g mysql -s /sbin/nologin -M mysql
2.創建安裝目錄/usr/local/mysql5.6 ,數據目錄/database,PID目錄/var/run/mysqld,日志目錄/var/log/mysqld。 配置文件目錄/usr/local/mysql5.6/etc 3.cmake -LH 產生CMakeCache.txt, 在make是就按這個cache文件來編譯(這樣全是默認,建議使用步驟4)。
4.制定CMakeCache.txt文件
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql5.6 \ 指定安裝路徑
-DMYSQL_DATADIR:PATH=/database \ 指定數據庫路徑
-DSYSCONFDIR:PATH=/usr/local/mysql5.6/etc \ 指定配置文件路徑
-DWITH_DEBUG:BOOL=on 開啟調試功能
5.編譯軟件make
6.安裝軟件make install
7.MySQL配置文件修改/usr/local/mysql5.6/etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.6
datadir=/database
socket=/var/run/mysqld/mysql5.6.sock
pid-file=/var/run/mysqld/mysql5.6.pid
port=3307 默認是3306
user=mysql
[mysqld_safe]
log-error=/var/log/mysqld/mysql5.6-error.log
8.給各個相關目錄賦予mysql權限
chown -R myslq.mysql /usr/local/mysql5.6 /database /var/run/mysqld/ /var/log/mysqld
9.執行mysql_install_db 腳本文件
/usr/local/mysql5.6/scripts/mysql_install_db --basedir=/usr/local/mysql5.6 --datadir=/database --user=mysql
10.復制啟動命令文件到系統目錄
cp /usr/local/mysql5.6/support-files/mysql.server /etc/rc.d/init.d/mysql5.6或/etc/init.d/mysqld
11.設置開機啟動mysql,和啟動myslqd
chkconfig --add mysql5.6
service mysql5.6 start
12.配置環境變量將/usr/local/mysql5u6/bin 添加到profile中
export PATH=$PATH:/usr/local/mysql5u6/bin
使文件生效
source /etc/profile

03-mysql-自動安裝腳本

#!/bin/bash
#comment
#./mysql-5.6.sh mysql-5.6.15.tar.gz
#:set ff=unix
#:set nobomb

name1="$1"
name2=${name1/.tar.gz/}

if ! grep -qi "^mysql" /etc/group; then
groupadd -g 27 mysql
fi

if ! id mysql >/dev/null 2>&1; then
useradd -u 27 -g mysql -s /sbin/nologin -M mysql
fi

yum install -y make cmake gcc gcc-c++ ncurses-devel bison >/dev/null 2>&1

[ -d /usr/local/mysql5.6 ] && rm -rf /usr/local/mysql5.6
[ -d /database ] && rm -rf /database/* || mkdir /database

if [ -d "$name2" ]; then
[ -e "$name2/CMakeCache.txt" ] && rm -f "$name2/CMakeCache.txt"
else
tar xf "$name1"
fi

cd $name2
#man cmake
#cmake -LH 產生CMakeCache.txt, make就按這個cache文件來編譯
#-D
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql5.6 \
-DMYSQL_DATADIR:PATH=/database \
-DSYSCONFDIR:PATH=/usr/local/mysql5.6/etc \
-DWITH_DEBUG:BOOL=on
make
make install

mkdir /usr/local/mysql5.6/etc

cat <<! >/usr/local/mysql5.6/etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.6
datadir=/database
socket=/var/run/mysqld/mysql5.6.sock
pid-file=/var/run/mysqld/mysql5.6.pid
port=3307
user=mysql

[mysqld_safe]
log-error=/var/log/mysqld/mysql5.6-error.log
!

[ -d /var/run/mysqld ] && rm -rf /var/run/mysqld/* || mkdir /var/run/mysqld
[ -d /var/log/mysqld ] && rm -rf /var/log/mysqld/* || mkdir /var/log/mysqld

chown -R mysql.mysql /usr/local/mysql5.6 /database /var/run/mysqld /var/log/mysqld

/usr/local/mysql5.6/scripts/mysql_install_db --basedir=/usr/local/mysql5.6 --datadir=/database --user=mysql

cp /usr/local/mysql5.6/support-files/mysql.server /etc/rc.d/init.d/mysql5.6
sed -i '/conf=/c conf=/usr/local/mysql5.6/etc/my.cnf' /etc/rc.d/init.d/mysql5.6

chkconfig --add mysql5.6
service mysql5.6 start

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved