標籤:
1. 首先卸載系統內建的 mysql
# yum remove mysql
2.安裝cmake
下載cmake源碼
# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
# tar xzfv cmake-2.8.5.tar.gz
# cd cmake-2.8.5
# ./configure
( 如果提示沒安裝C++編譯器就先安裝C++編譯器:# yum -y install gcc-c++ )
# make
# make install
查看 cmake 版本
# cmake -version
3.安裝 ncurses 和 bison
# yum -y install ncurses-devel
# yum -y install bison
4. 建立mysql組和使用者
# groupadd mysql
# useradd -g mysql mysql
5. 建立資料庫目錄及分配存取權限
# mkdir -p /u01/app/mysql
# chown -R root:mysql /u01/app/mysql
# chown -R mysql:mysql /u01/app/mysql/data
6. 編譯安裝mysql
下載mysql源碼
# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz
# tar xzfv mysql-5.6.20.tar.gz
# cd mysql-5.6.20
# cmake . -DCMAKE_INSTALL_PREFIX=/u01/app/mysql -DMYSQL_DATADIR=/u01/app/mysql/data -DSYSCONFDIR=/etc
參數說明:
-DCMAKE_INSTALL_PREFIX //安裝根目錄
-DINSTALL_DATADIR //資料存放區目錄
-DSYSCONFDIR //設定檔(my.cnf)目錄
# make
# make install
7. 配置 mysql
# cd /u01/app/mysql
# cp ./support-files/my-default.cnf /etc/my.cnf
# vi /etc/my.cnf
在 [mysqld] 段修改
basedir = /u01/app/mysql
datadir = /u01/app/mysql/data
儲存退出編輯。
8. 初始化資料庫
# cd /u01/app/mysql
# ./scripts/mysql_install_db --basedir=/u01/app/mysql --datadir=/u01/app/mysql/data --defaults-file=/etc/my.cnf --user=mysql
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
9. 設定啟動指令碼變數
# vi /etc/rc.d/init.d/mysqld
basedir=/u01/app/mysql
datadir=/u01/app/mysql/data
儲存退出。
10. 設定變數環境
# echo "PATH=$PATH:/u01/app/mysql/bin" >> /etc/profile (永久生效)
# export PATH=$PATH:/u01/app/mysql/bin (當前生效)
11. 啟動服務
# service mysqld start
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Starting MySQL. [ OK ]
12. 設定資料庫管理員root密碼
# mysqladmin -u root password ‘123456‘
(註:在當前會話視窗操作,否則會出現 “mysqladmin: command not found” 錯誤,除非重新啟動系統。)
重新啟動服務
# service mysqld restart
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Shutting down MySQL. [ OK ]
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Starting MySQL. [ OK ]
13. 進入 MySQL
# mysql -u root -p
(註:在當前會話視窗操作,否則會出現 “mysql: command not found” 錯誤,除非重新啟動系統。)
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.20 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered 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>
登入成功了,趕快感受一下 :)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select Host,User,Password from user;
+-----------------------+------+-------------------------------------------+
| Host | User | Password |
+-----------------------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| localhost.localdomain | | |
+-----------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql>
Mysql源碼編譯安裝