1. 文檔說(shuō)明
簡(jiǎn)述mysql數(shù)據(jù)庫(kù)基礎(chǔ)安裝配置手冊(cè)钞诡,性能調(diào)優(yōu)需要結(jié)合my.cnf的參數(shù)進(jìn)行調(diào)優(yōu)萍诱,將在其他文檔中進(jìn)行介紹,安裝配置需要注意mysql軟件介質(zhì)目錄和數(shù)據(jù)目錄的規(guī)劃券盅;編譯安裝要求對(duì)編譯環(huán)境足夠熟悉霸褒,因此不建議生產(chǎn)環(huán)境使用編譯安裝的方式。
2. 參考文檔
mysql reference手冊(cè)
3. 系統(tǒng)準(zhǔn)備
操作系統(tǒng):centos 6.5(mini desktop安裝)
mysql:mysql 5.7.{16绽媒,17蚕冬,18}
Item | Item Content |
---|---|
IP | 192.168.4.192 |
HOSTNAME | node2.mono |
MYSQL_HOME | /opt/mysql/5.7.16 |
DATA DIR | /mysql/data |
BINLOG DIR | /mysql/binlog |
MY.CNF DIR | /etc/my.cnf |
Notes:mysql數(shù)據(jù)庫(kù)對(duì)目錄結(jié)構(gòu)并無(wú)要求,操作中使用結(jié)構(gòu)清晰的目錄方便理解和操作簡(jiǎn)便性是辕;除了RPM包安裝不能使用自定義MYSQL_HOME囤热,其他安裝配置方式都可以自定義MYSQL_HOME。
4.1 安裝介質(zhì)準(zhǔn)備
boost c++庫(kù)源碼:
https://sourceforge.net/projects/boost/files/boost/
mysql 5.7使用的boost 1_59_0
mysql源碼:
4.2 系統(tǒng)用戶創(chuàng)建
groupadd -g 270 mysql
useradd -u 271 -g mysql -s /bin/bash -d /home/mysql -m mysql
4.3 相關(guān)目錄創(chuàng)建
mkdir -p /mysql/{data,binlog}
mkdir -p /opt/mysql/5.7.18
4.4 編譯環(huán)境準(zhǔn)備
安裝編譯工具鏈需要的依賴
yum -y install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs Python-devel zlib-devel
yum -y install gcc-c++ ncurses-devel cmake make perl \
gcc autoconf automake zlib libxml libgcrypt libtool bison
4.5 mysql編譯安裝
檢查是否已有mysql組件
[root@node1 ~]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
#卸載已經(jīng)存在的mysql組件
rpm -e mysql-libs-5.1.71-1.el6.x86_64 –nodeps
上傳boost源碼和mysql源碼至root目錄
cd /root
sftp> put boost_1_59_0.tar.gz
sftp> put mysql-boost-5.7.18.tar.gz
解壓mysql源碼介質(zhì)
tar -zxvf mysql-5.7.18.tar.gz
編譯mysql源碼介質(zhì)
cd mysql-5.7.18
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql/5.7.18 -DMYSQL_DATADIR=/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1
make
#make的時(shí)間會(huì)比較長(zhǎng)获三,大概需要真的需要1個(gè)小時(shí)旁蔼,且在中間會(huì)產(chǎn)生一些warning信息
make install
mysql有許多預(yù)編譯參數(shù),在生產(chǎn)環(huán)境使用時(shí)疙教,需要對(duì)這些參數(shù)把握比較大的時(shí)候方可使用棺聊。
4.6 mysql配置
配置實(shí)例參數(shù)文件/etc/my.cnf
vi /etc/my.cnf
[mysqld_safe]
log-error = /mysql/mysqld.log
[mysqld]
log_bin = /mysql/binlog/mysql-bin.log
basedir = /opt/mysql/5.7.18
datadir = /mysql/data
port = 3306
server_id = 1
socket = /tmp/mysqld.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /tmp/mysqld.sock
配置服務(wù)參數(shù)文件/etc/init.d/mysqld
cd /root/mysql-5.7.18/support-files/
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
修改/etc/init.d/mysqld
vi /etc/init.d/mysqld
basedir=/opt/mysql/5.7.18
datadir=/mysql/data
# Lock directory for RedHat / SuSE.
lockdir='/mysql'
lock_file_path="$lockdir/mysqld.loc"
授權(quán)相關(guān)目錄和文件
chown mysql.mysql -R /mysql
chown mysql.mysql -R /opt/mysql
chown mysql.mysql -R /etc/my.cnf
chown mysql.mysql -R /etc/init.d/mysqld
msyql用戶環(huán)境變量配置
su – mysql
vi ~/.bash_profile
# Set for mysql database
export MYSQL_HOME=/opt/mysql/5.7.18
PATH=$PATH:$HOME/bin:$MYSQL_HOME/bin
source ~/.bash_profile
4.7 mysql初始化
su – mysql
mysqld –defaults-file=/etc/my.cnf –-initialize –-user=mysql
記住初始化時(shí)產(chǎn)生的臨時(shí)密碼
4.8 mysql進(jìn)程啟動(dòng)
su - mysql
/etc/init.d/mysqld start
4.9 root密碼修改
su – msyql
mysql -uroot -p
alter user ‘root’@’localhost’ identified by ‘mysql*123’;