標籤:mysql源碼包編譯安裝
在編譯安裝mysql之前,先瞭解一下mysql具體是做啥的。
1、Mysql是一個開放源碼的小型關係型資料庫管理系統,開放者為瑞典MYSQL AB公司,目前MYSQL被廣泛地應用在Internet上的中小型網站中。由於其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,許多種小型網站為降低網站總體擁有的成本而選擇了MYSQL作為網站資料庫。
2、安裝 Mysql
2.1、安裝簡介
使用者名稱:mysql
安裝目錄:/usr/local/mysql
資料庫目錄:/usr/local/data/mysql/data
源碼包:mysql-5.6.24.tar.gz
2.2、添加使用者
useradd -s /sbin/nologin mysql
2.3、建立所需目錄
mkdir /usr/local/mysql
mkdir -p /usr/local/data/mysql/data
chown -R mysql:mysql /usr/local/data/mysql/data
2.4、安裝編譯所需檔案或程式
yum install gcc gcc-c++ cmake ncurses-devel bison
2.5、mysql下載網址
mysql源碼包下載連結http://dev.mysql.com/downloads/mysql/5.7.html
mysql參考手冊http://dev.mysql.com/doc/
2.6、編譯安裝
下載mysql源碼包後,該源碼包在root的目錄下
cd /root
tar -zxvf mysql-5.6.24.tar.gz
cd mysql-5.6.24
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1
make && make install
2.7、編譯安裝mysql後,添加許可權
chown -R mysql:mysql /usr/local/mysql
mv /root/mysql-5.6.24/support-files/mysql-default.conf /etc/my.cnf
mv /root/mysql-5.6.24/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
2.8、設定mysql服務為開機啟動
chkconfig --level 345 mysqld on echo "export PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile
source /etc/profile
2.9初始化資料庫
/usr/local/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/data/mysql/data
vi /etc/my.cnf(在檔案最後添加下面兩個語句)
basedir=/usr/local/mysql
datadir=/usr/local/data/mysql/data
3、啟動資料庫
service mysqld start
3.1、建立mysql管理員
/usr/local/mysql/bin/mysqladmin -u root password ‘123456‘
-------------------------------------------------------------------------------------------
下面開始安裝
[BEGIN] 2015/12/18 22:03:34[[email protected] ~]# mkdir -p /usr/local/data/mysql/data [[email protected] ~]# useradd -s /sbin/nologin mysql [[email protected] ~]# chown -R mysql:mysql /usr/local/data/mysql/data [[email protected] ~]# yum install gcc gcc-c++ cmake ncurses-devel bison [[email protected] ~]# tar -zxvf mysql-5.6.24.tar.gz [[email protected] ~]# cd mysql-5.6.24 [[email protected] mysql-5.6.24]# mkdir /usr/local/mysql [[email protected] mysql-5.6.24]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 ()[[email protected] mysql-5.6.24]# make [[email protected] mysql-5.6.24]# make install [[email protected] mysql-5.6.24]# chown -R mysql:mysql /usr/local/mysql/ [[email protected] mysql-5.6.24]# mv /root/mysql-5.6.24/support-files/my-default.cnf /etc/my.cnf [[email protected] mysql-5.6.24]# mv /root/mysql-5.6.24/support-files/mysql.server /etc/init.d/mysqld[[email protected] mysql-5.6.24]# chmod a+x /etc/init.d/mysqld[[email protected] mysql-5.6.24]# chkconfig --level 345 mysqld on[[email protected] mysql-5.6.24]# echo "export PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile[[email protected] mysql-5.6.24]# source /etc/profile[[email protected] mysql-5.6.24]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/data/mysql/data[[email protected] mysql-5.6.24]# vi /etc/my.cnf [[email protected] mysql-5.6.24]# service mysqld startStarting MySQL... SUCCESS! [[email protected] mysql-5.6.24]# /usr/local/mysql/bin/mysqladmin -u root password ‘123456‘[[email protected] mysql-5.6.24]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.24 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> exitBye
mysql-5.6.24源碼包編譯安裝