標籤:mysql
centos6.6 編譯安裝MySQL5.6
【本文檔所介紹的內容適用於公司測試/生產等常見的MySQL資料庫環境部署】
一:環境部署前準備:
1.1相關軟體以及系統
系統要求:Centos 6.6 (64位)
相關中介軟體: mysql-5.6.23
1.2相關係統依賴包安裝檢查準備
1.2.1 檢查系統內建mysql是否安裝
# rpm -qa | grep mysql
如有安裝,請使用以下命令卸載相關程式
# yum remove mysql
1.2.2 安裝系統相關的編譯環境:mysql編譯前需要的依賴包
yum install gcc gcc-c++ cmake autoconf automake ncurses-devel libmcrypt* libtool* zlib* libxml* openssl openssl-devel
二:MySQL環境部署正式安裝:
2.1編譯安裝MySQL
MySQL從5.5版本開始,通過./configure進行編譯配置方式已經被取消,取而代之的是cmake工具編譯。
因此,我們首先要在系統中源碼編譯安裝cmake工具,安裝cmake時可以源碼安裝也可以yum 安裝,這裡採用的yum形式安裝cmake
2.1.1 mysql安裝前準備(安裝mysql前先需要添加相關的mysql運行帳號及相關安裝目錄和許可權)
<--添加mysql運行帳號-->
# groupadd mysql //添加mysql服務組帳號;# useradd -g mysql -M -s /sbin/nologin mysql //添加mysql服務服務帳號,設定不登陸系統;
<--添加mysql程式相關目錄-->
# mkdir -p /usr/local/mysql //建立mysql安裝目錄;# mkdir -p /usr/local/mysql/data //建立mysql資料存放目錄;
2.1.2編譯安裝mysql(預設包放在/root目錄下,包統一解壓到/usr/local/src)
# tar -zxvf mysql-5.6.23.tar.gz -C /usr/local/src/# cd /usr/local/src/mysql-5.6.23/# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/etc -DWITH_SSL=yes# make && make install
《提示:如果以上編譯編譯失敗的話,重新編譯需要再執行以下命令,並清除相關檔案,內容如下:
# make clean# rm -f CMakeCache.txt
2.1.3 給mysql相關目錄設定屬主許可權
# chown -R mysql:mysql /usr/local/mysql //設定mysql安裝目錄的屬主;# chown -R mysql:mysql /usr/local/mysql/data //設定mysql資料存放目錄的屬主;
2.1.4 初始化mysql資料庫準備
# cd /usr/local/mysql/ //設定mysql安裝目錄的屬主;# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql //初始化mysql資料庫;
2.1.5 添加mysql資料庫設定檔範本
# cd /usr/local/mysql/ //進入到安裝目錄拷貝資料庫範例模板;# cp support-files/my-medium.cnf /etc/my.cnf //這裡範例模板可以是生產也可以是開發;
2.1.6 添加mysql服務啟動到系統服務裡,並最佳化mysql命令調用
<--添加mysql服務啟動到系統服務,並開機自啟動-->
# cd /usr/local/mysql/# cp support-files/mysql.server /etc/init.d/mysqld //拷貝mysql服務指令碼到系統;# vim /etc/init.d/mysqld 找到如下內容並添加相關路徑 basedir=/usr/local/mysql //mysql安裝目錄; datadir=/usr/lcoal/mysql/data //mysql資料存放目錄;# chkconfig -add mysqld //添加mysql服務到系統服務;# chkconfig --level 235 mysqld on //設定mysql開機自啟動;
<--最佳化mysql命令調用-->
修改/etc/profile檔案,在檔案末尾添加
# PATH=/usr/local/mysql/bin:$PATH# export PATH# wq! //儲存# source /etc/profile
2.1.7 啟動mysql服務,並設定管理員帳號密碼
# service mysqld start //啟動MySQL資料庫服務# mysql_secure_installation //對MySQL進行安全設定(包括資料庫密碼以及相關的庫使用權限設定)<-------此處省略---------> //這裡是運行後相關的提示資訊Enter current password for root (enter for none): OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.You already have a root password set, so you can safely answer ‘n‘.Change the root password? [Y/n] y (設定MySQL管理員root密碼)New password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!Remove anonymous users? [Y/n] y (移除匿名使用者,選擇Y) ... Success!<-------此處省略--------->Disallow root login remotely? [Y/n] y (移除管理員遠端存取許可權,選擇Y) ... Success!<-------此處省略--------->Remove test database and access to it? [Y/n] y (移除test測試資料庫,選擇Y)<-------此處省略--------->Reload privilege tables now? [Y/n] y (重新整理資料庫許可權,選擇Y) ... Success!Cleaning up...
三:測試資料庫是否可以正常工作
# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 29269Server version: 5.5.43-log Source distributionCopyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
看到這些提示,說明MySQL已經正常運行,MySQL環境編譯安裝ok!
CentOS 6.4下編譯安裝MySQL 5.6.14
本文出自 “菜鳥的成長記” 部落格,請務必保留此出處http://blief.blog.51cto.com/6170059/1671119
Linux之mysql的編譯安裝(1)