1. 程式人生 > >linux CenterOS 下 mysql-5.6.26.tar.gz原始碼安裝

linux CenterOS 下 mysql-5.6.26.tar.gz原始碼安裝

1.準備工作

[[email protected]]# cd /cnpc/

百度雲盤 mysql-5.6.26.tar.gz連結:http://pan.baidu.com/s/1dDe9ifv 密碼:ifus

[[email protected] cnpc]# tar zxvf mysql-5.6.26.tar.gz //解壓檔案

[[email protected]]# ls 

hadoop-2.2.0  mysql-5.6.26 mysql-5.6.26.tar.gz

[[email protected]]# cd mysql-5.6.26

2.必要軟體包

[[email protected]

]# yum -y install  gccgcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt*libtool-ltdl-devel* make cmake

3.編譯安裝

#預設情況下是安裝在/usr/local/mysql

[[email protected]]# cmake .

出錯了!!!!

-- Configuring incomplete, errors occurred!

See also"/cnpc/mysql-5.6.26/CMakeFiles/CMakeOutput.log".

See also"/cnpc/mysql-5.6.26/CMakeFiles/CMakeError.log".

#如果cmake期間碰到上述錯誤,應該安裝ncurses-develrpm包,然後移除CMakeCache.txt,反之跳過

[[email protected] mysql-5.6.26]# yum -y installncurses-devel

[[email protected] mysql-5.6.26]# find / -nameCMakeCache.txt

/cnpc/mysql-5.6.26/CMakeCache.txt

[[email protected] mysql-5.6.26]# rm -rf/cnpc/mysql-5.6.26/CMakeCache.txt

[[email protected] mysql-5.6.26]# cmake .

[[email protected]]# make && make install

注:

cmake .  的預設配置如下(不需要執行)

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

4.新增使用者

[[email protected]]# groupadd mysql

[[email protected]]# useradd -r -g mysql mysql

修改目錄所有者

[[email protected]]# chown -R mysql.mysql /usr/local/mysql

5.初始化資料庫

[[email protected]]# cd /usr/local/mysql/scripts

[[email protected]]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data

6.註冊服務

[[email protected]]# cd /usr/local/mysql/support-files

[[email protected] support-files]# cp mysql.server /etc/rc.d/init.d/mysql        //註冊服務

[[email protected] support-files]# cp my-default.cnf /etc/my.cnf       //使用預設配置檔案

cp: overwrite `/etc/my.cnf'?y(這裡得注意了,輸入y覆蓋,如果你直接回車,表示不覆蓋,以後面啟動service mysql start 可能會出現以下錯誤)

Starting MySQL. ERROR! Theserver quit without updating PID file (/var/lib/mysql/cnpc01.pid).

[[email protected] support-files]# chkconfig --add mysql        //讓chkconfig管理mysql 服務

[[email protected] support-files]# chkconfig mysql on            //開機啟動

[[email protected]]# service mysql start

Starting MySQL.. SUCCESS!   //初步啟動成功

7.mySql管理員root預設密碼為空,需要修改

[[email protected] support-files]# /usr/local/mysql/bin/mysqladmin -u rootpassword 'newpassword '

測試連線mysql

[[email protected]~]# cd /usr/local/mysql/bin/

[[email protected]]# ./mysql -u root -p

Enterpassword:

Welcome to theMySQL monitor.  Commands end with ; or\g.

Your MySQLconnection id is 2

Serverversion: 5.6.26 Source distribution

Copyright (c)2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is aregistered trademark of Oracle Corporation and/or its

affiliates.Other names may be trademarks of their respective

owners.

Type 'help;'or '\h' for help. Type '\c' to clear the current input statement.

mysql> showdatabases;

+--------------------+

|Database           |

+--------------------+

|information_schema |

| mysql              |

|performance_schema |

| test               |

+--------------------+

4 rows in set(0.06 sec)

8.如果需要遠端訪問,執行如下語句

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

大功告成!

遇到如下錯誤有多種解決辦法

Starting MySQL. ERROR!The server quit without updating PID file (/var/lib/mysql/cnpc01.pid).

我是使用如下 方式解決的(第4種方法),我在網上找了下資料,大概有7種,不行了就一個個試試,總會有解決的辦法的

[[email protected]]# vi /etc/my.cnf

[mysqld]

#datadir=/var/lib/mysql修改前

datadir = /usr/local/mysql/data  //修改後

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disablingsymbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

1.可能是/usr/local/mysql/data/rekfan.pid檔案沒有寫的許可權

解決方法 :給予許可權,執行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data”  然後重新啟動mysqld!

2.可能程序裡已經存在mysql程序

解決方法:用命令“ps -ef|grep mysqld”檢視是否有mysqld程序,如果有使用“kill -9  程序號”殺死,然後重新啟動mysqld!

3.可能是第二次在機器上安裝mysql,有殘餘資料影響了服務的啟動。

解決方法:去mysql的資料目錄/data看看,如果存在mysql-bin.index,就趕快把它刪除掉吧,它就是罪魁禍首了。

4.mysql在啟動時沒有指定配置檔案時會使用/etc/my.cnf配置檔案,請開啟這個檔案檢視在[mysqld]節下有沒有指定資料目錄(datadir)。

解決方法:請在[mysqld]下設定這一行: datadir =/usr/local/mysql/data,參考你安裝時執行的命令

./mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

5.skip-federated欄位問題

解決方法:檢查一下/etc/my.cnf檔案中有沒有沒被註釋掉的skip-federated欄位,如果有就立即註釋掉吧。

6.錯誤日誌目錄不存在

解決方法:使用“chown” “chmod”命令賦予mysql所有者及許可權

7.selinux惹的禍,如果是centos系統,預設會開啟selinux

解決方法:關閉它,開啟/etc/selinux/config,把SELINUX=enforcing改為SELINUX=disabled後存檔退出重啟機器試試