[linux]linux下安裝mysql

風痕影默發表於2014-12-17

1、安裝g++
$sudo apt-get install build-essential
注:此命令會同時安裝gcc和make
2、安裝cmake
$sudo apt-get install cmake
3、安裝mysql
進入mysql檔案所在目錄(cd)
$unzip mysql-5.6.4-m7.tar\(1\).zip
$tar -zxvf mysql-5.6.4-m7.tar.gz
進入mysql-5.6.4-m7
$cd mysql-5.6.4-m7
$groupadd mysql //所以在這裡我們要建一個msyql的使用者和組
$useradd -g mysql mysql -s /usr/sbin/nologin
$mkdir /usr/local/mysql //建立目錄
$mkdir /usr/local/mysql/data
$cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql && make && make install
此時可以會出錯,提示缺少ncurses library之類的,輸入以下命令來安裝
$sudo apt-get install libncurses5-dev
然後刪除目錄中的CMakeCache.txt
$sudo rm CMakeCache.txt
繼續操作輸入cmake -DCMAKE....這條命令就安裝成功了
4、配置mysql
進入mysql的安裝目錄/usr/local/mysql下:
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql //初始化mysql資料庫
cp support-files/my-medium.cnf /usr/local/mysql/my.cnf //copy配置檔案
chown -R mysql:mysql /usr/local/mysql //更改許可權
vi /usr/local/mysql/my.cnf //加上以下內容

[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp

啟動mysql bin/mysqld_safe --user=mysql & 或使用下列命令把mysql新增為系統服務。
cd /usr/local/mysql/support-files/
cp ./mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start

相關文章