Mysql源碼編譯安裝

來源:互聯網
上載者:User

標籤:

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源碼編譯安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.