centos編譯安裝mysql5.5
安裝Mysql5.5之前先卸載CentOS自帶的Mysql5.0。
[root@localhost ~]# yum remove mysql
編譯安裝cmake www.2cto.com
下載cmake源碼包cmake-2.8.4.tar.gz,mv到/usr/local/src目錄下
[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# tar xzvf cmake-2.8.4.tar.gz [root@localhost src]# cd cmake-2.8.4 [root@localhost cmake-2.8.4]# ./bootstrap --------------------------------------------- CMake 2.8.4, Copyright 2000-2009 Kitware, Inc. --------------------------------------------- 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. --------------------------------------------- Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log ---------------------------------------------
報錯:缺少C的編譯器。 www.2cto.com
安裝gcc編譯器
可以從Linux系統的安裝盤中安裝,也可以簡單地用yum安裝
[root@localhost ~]# yum install gcc
繼續cmake的安裝
[root@localhost cmake-2.8.4]# ./bootstrap --------------------------------------------- CMake 2.8.4, Copyright 2000-2009 Kitware, Inc. C compiler on this system is: cc --------------------------------------------- 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. --------------------------------------------- Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log ---------------------------------------------
再次報錯:缺少C++編譯器。
安裝gcc-c++編譯器 www.2cto.com
同樣可以從Linux系統的安裝盤中安裝,或者簡單地用yum安裝
[root@localhost ~]# yum install gcc-c++
重復上面的操作
[root@localhost cmake-2.8.4]# ./bootstrap
沒有報錯後,編譯安裝
[root@localhost cmake-2.8.4]# gmake [root@localhost cmake-2.8.4]# gmake install
開始正式安裝Mysql
添加mysql用戶和用戶組
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -g mysql mysql
下載mysql的源碼包mysql-5.5.11.tar.gz到/usr/local/src下,解壓
[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# tar xzvf mysql-5.5.11.tar.gz [root@localhost src]# cd mysql-5.5.11
cmake運行
[root@localhost mysql-5.5.11]# cmake .
報錯: www.2cto.com
-- 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!
缺少Curses包,解決辦法:remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.很容易看懂,不解釋了...
在CentOS下需要安裝ncurses-devel
[root@localhost mysql-5.5.11]# yum install ncurses-devel
重新cmake運行
[root@localhost mysql-5.5.11]# cmake .
www.2cto.com
還是有個警告
Warning: Bison executable not found in PATH
有一個警告,也解決了它,缺少Bison就安裝一下
[root@localhost mysql-5.5.11]# yum install bison
再次運行,沒有報錯
[root@localhost mysql-5.5.11]# cmake .
在編譯安裝前,可以設置安裝的配置選項
[root@localhost mysql-5.5.11]# ./configure --help
根據幫助信息選擇自己需要設置的選項,當然也可以跳過這步,按默認設置
開始編譯安裝,時間有點稍長,可以泡杯咖啡轉悠一下...
[root@localhost mysql-5.5.11]# make && make install
完成編譯安裝 www.2cto.com
進入安裝目錄,將程序二進制的所有權改為root,數據目錄的說有權改為mysql用戶,更新授權表
[root@localhost mysql-5.5.11]# 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
安全啟動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
有3種方法為root賬戶設置密碼:
www.2cto.com
使用SET PASSWORD語句
[root@localhost ~]# mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd'); mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd')
使用mysqladmin命令行程序
[root@localhost ~]# mysqladmin -u root password "newpwd" [root@localhost ~]# mysqladmin -u root -h host_name password "newpwd"
使用UPDATE語句
[root@localhost ~]# mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd') -> WHERE User = 'root'; mysql> FLUSH PRIVILEGES;
其他設置處理:
設置選項文件,將配置文件拷貝到/etc下
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf
設置開機自啟動 www.2cto.com
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@localhost mysql]# chmod +x /etc/init.d/mysql
現在可以通過服務來啟動和關閉Mysql
[root@localhost ~]# service mysql start [root@localhost ~]# service mysql shutdown
基本上的安裝就是這樣了