打開終端
切換到根目錄
[shell@localhost ~]# su -安裝Mysql5.5之前先卸載CentOS自帶的Mysql5.0。
[root@localhost ~]# yum remove mysql
安裝cmake
下載cmake源碼包cmake-2.8.5.tar.gz
[root@localhost ~]# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz編譯安裝[root@localhost]# tar xzvf cmake-2.8.5.tar.gz [root@localhost]# cd cmake-2.8.5 [root@localhost cmake-2.8.5]# ./bootstrap Error when bootstrapping CMake: Cannot find appropriate C compiler on this system. Please specify one using environment variable CC. See cmake_bootstrap.log for compilers attempted. 報錯:缺少C的編譯器。
解決方法:安裝gcc編譯器
可以從Linux系統的安裝盤中安裝,也可以簡單地用yum安裝
[root@localhost ~]# yum install gcc
繼續cmake的安裝
[root@localhost cmake-2.8.5]# ./bootstrap Error when bootstrapping CMake: Cannot find appropriate C++ compiler on this system. Please specify one using environment variable CXX. See cmake_bootstrap.log for compilers attempted. 再次報錯:缺少C++編譯器。
安裝gcc-c++編譯器
同樣可以從Linux系統的安裝盤中安裝,或者簡單地用yum安裝
[root@localhost ~]# yum install gcc-c++
重復上面的操作
[root@localhost cmake-2.8.5]# ./bootstrap
沒有報錯後,編譯安裝
[root@localhost cmake-2.8.5]# make [root@localhost cmake-2.8.5]# make install[root@localhost cmake-2.8.5]# cmake -version
開始正式安裝Mysql
添加mysql用戶和用戶組
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -g mysql mysql
下載mysql的源碼包mysql-5.5.27.tar.gz
[root@localhost ~]# wget http://dev.mysql.com/Downloads/MySQL-5.5/mysql-5.5.27.tar.gz解壓
[root@localhost ~]# cd /usr/local/[root@localhost local]# tar xzvf mysql-5.5.27.tar.gz[root@localhost local]# cd mysql-5.5.27
cmake運行
[root@localhost mysql-5.5.27]# cmake .
報錯:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:82 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. Call Stack (most recent call first): cmake/readline.cmake:126 (FIND_CURSES) cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT) CMakeLists.txt:250 (MYSQL_CHECK_READLINE) -- Configuring incomplete, errors occurred!
解決辦法:
[root@localhost mysql-5.5.27]# rm CMakeCache.txt [root@localhost mysql-5.5.27]# yum -y install ncurses-devel*
重新cmake運行
[root@localhost mysql-5.5.27]# cmake .還是有個警告
Warning: Bison executable not found in PATH有一個警告,也解決了它,缺少Bison就安裝一下
[root@localhost mysql-5.5.27]# yum install bison
再次運行,沒有報錯
[root@localhost mysql-5.5.27]# cmake .在編譯安裝前,可以設置安裝的配置選項
[root@localhost mysql-5.5.27]# ./configure --help根據幫助信息選擇自己需要設置的選項,當然也可以跳過這步,按默認設置
#開始編譯安裝,時間有點稍長...
[root@localhost mysql-5.5.27]# make && make install完成編譯安裝
進入安裝目錄,將程序二進制的所有權改為root,數據目錄的所有權改為mysql用戶,更新授權表
[root@localhost mysql-5.5.27]# cd /usr/local/mysql[root@localhost mysql]# chown -R root . [root@localhost mysql]# chown -R mysql . [root@localhost mysql]# chgrp -R mysql . [root@localhost mysql]# scripts/mysql_install_db --user=mysql 初始化數據庫[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 安全啟動mysql
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql關閉mysql
[root@localhost mysql]# ./bin/mysqladmin -u root shutdown -p默認密碼為空方便調用,為mysql設置一個軟鏈接[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
其他設置處理:
設置選項文件,將配置文件拷貝到/etc下
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf 設置開機自啟動[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@localhost mysql]# chmod +x /etc/init.d/mysql [root@localhost mysql]# chkconfig –add mysqld[root@localhost mysql]# chkconfg mysqld on
現在可以通過服務來啟動和關閉Mysql服務器
[root@localhost ~]# service mysql start [root@localhost ~]# service mysql shutdown
連接服務器
[root@localhost ~]# mysql -u root -pyourpasswordWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3 to server version: 5.5.27 Source distributinoType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> ...mysql> 提示符告訴你mysql准備為你輸入命令。
至此MySQL已經正常安裝並可以使用
mysql> QUIT