Centos成功安裝mysql-5.5.37

來源:互聯網
上載者:User

標籤:資料庫   伺服器   centos   mysql   架構   

            摘自http://www.2cto.com/os/201404/296364.html(原文請關注)

這幾天在centos下裝mysql,這裡記錄一下安裝的過程,方便以後查閱

Mysql5.5.37安裝需要cmake,5.6版本開始都需要cmake來編譯,5.5以後的版本應該也要裝這個。

安裝cmake

[plain] view plaincopyprint?01.[[email protected] ~]# wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz 
02.[[email protected] ~]# tar xvf cmake-2.8.12.2.tar.gz 
03.[[email protected] ~]# cd cmake-2.8.12.2 
04.[[email protected] cmake-2.8.12.2]#./bootstrap 
05.[[email protected] cmake-2.8.12.2]# make 
06.[[email protected] cmake-2.8.12.2]# make install 
[[email protected] ~]# wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
[[email protected] ~]# tar xvf cmake-2.8.12.2.tar.gz
[[email protected] ~]# cd cmake-2.8.12.2
[[email protected] cmake-2.8.12.2]#./bootstrap
[[email protected] cmake-2.8.12.2]# make

[[email protected] cmake-2.8.12.2]# make install 安裝mysql

[plain] view plaincopyprint?01.[[email protected] ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz 
02.[[email protected] ~]# tar xvf mysql-5.5.37.tar.gz 
03.[[email protected] ~]# cd mysql-5.5.37 
04.[[email protected] mysql-5.5.37]# cmake ./ 
[[email protected] ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz
[[email protected] ~]# tar xvf mysql-5.5.37.tar.gz
[[email protected] ~]# cd mysql-5.5.37
[[email protected] mysql-5.5.37]# cmake ./

可能還會報這個錯,沒有就跳過

[plain] view plaincopyprint?01.CMake Error at cmake/readline.cmake:83(MESSAGE): 
02.Curses library not found.  Pleaseinstall appropriate package, 
03.remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name islibncurses5-dev, on Redhat and derivates it is ncurses-devel. 
04.Call Stack (most recent call first): 
05. cmake/readline.cmake:127 (FIND_CURSES) 
06. cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT) 
07. CMakeLists.txt:355 (MYSQL_CHECK_READLINE 
08.-- Configuring incomplete, errors occurred! 
09.See also "/root/my/mysql-5.5.37/CMakeFiles/CMakeOutput.log". 
10.See also"/root/my/mysql-5.5.37/CMakeFiles/CMakeError.log". 
CMake Error at cmake/readline.cmake:83(MESSAGE):
Curses library not found.  Pleaseinstall appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name islibncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
 cmake/readline.cmake:127 (FIND_CURSES)
 cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
 CMakeLists.txt:355 (MYSQL_CHECK_READLINE
-- Configuring incomplete, errors occurred!
See also "/root/my/mysql-5.5.37/CMakeFiles/CMakeOutput.log".
See also"/root/my/mysql-5.5.37/CMakeFiles/CMakeError.log".

說明centos系統沒有ncurses-devel

[plain] view plaincopyprint?01.[[email protected] ~]# wgethttp://invisible-island.net/datafiles/release/ncurses.tar.gz 
02.[[email protected] ~]# cd ncurses-5.9 
03.[[email protected] ncurses-5.9]#./configure 
04.[[email protected] ncurses-5.9]# make 
05.[[email protected] ncurses-5.9]# make install 
[[email protected] ~]# wgethttp://invisible-island.net/datafiles/release/ncurses.tar.gz
[[email protected] ~]# cd ncurses-5.9
[[email protected] ncurses-5.9]#./configure
[[email protected] ncurses-5.9]# make
[[email protected] ncurses-5.9]# make install

再刪除剛才編譯產生的 CMakeCache.txt 檔案,否則無法進行下一步

[plain] view plaincopyprint?01.[[email protected] mysql-5.5.37]# rm -f CMakeCache.txt 
[[email protected] mysql-5.5.37]# rm -f CMakeCache.txt

繼續編譯mysql

[plain] view plaincopyprint?01.[[email protected] ~]# cmake ./ 
02.[[email protected] ~]# make 
03.[[email protected] ~]# make install 
[[email protected] ~]# cmake ./
[[email protected] ~]# make
[[email protected] ~]# make install

這樣,mysql預設將成功安裝到/usr/local/mysql

建立mysql使用者組

[plain] view plaincopyprint?01.[[email protected] ~]# groupadd mysql 
02.[[email protected] ~]# useradd –r –g mysql mysql 
03.[[email protected] ~]# chown –R mysql.mysql /usr/local/mysql 
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd –r –g mysql mysql
[[email protected] ~]# chown –R mysql.mysql /usr/local/mysql

啟動mysql

[plain] view plaincopyprint?01.[[email protected] ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql 
[[email protected] ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql

這裡可能會發生錯誤,沒有就跳過:

[plain] view plaincopyprint?01.FATAL ERROR: Could not find./bin/my_print_defaults 
02.If you compiled from source, you need torun ‘make install‘ to 
03.copy the software into the correct locationready for operation. 
04.If you are using a binary release, you musteither be at the top 
05.level of the extracted archive, or pass the --basedir option 
06.pointing to that location. 
FATAL ERROR: Could not find./bin/my_print_defaults
If you compiled from source, you need torun ‘make install‘ to
copy the software into the correct locationready for operation.
If you are using a binary release, you musteither be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

解決方案:

[plain] view plaincopyprint?01.[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 
[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

再啟動mysql

[plain] view plaincopyprint?01.[[email protected] ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql 
[[email protected] ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql

註冊mysql服務,開機自動啟動

1.設定mysql設定檔到/etc目錄

[plain] view plaincopyprint?01.[[email protected] ~]# cp /usr/local/mysql/support-files/my-medium.cnf/etc/my.cnf 
[[email protected] ~]# cp /usr/local/mysql/support-files/my-medium.cnf/etc/my.cnf

2.設定mysql開機自啟

[plain] view plaincopyprint?01.[[email protected] ~]# cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
02.[[email protected] ~]# chmod +x /etc/init.d/mysql 
03.[[email protected] ~]# /sbin/chkconfig --add mysql 
[[email protected] ~]# cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[[email protected] ~]# chmod +x /etc/init.d/mysql
[[email protected] ~]# /sbin/chkconfig --add mysql

3.啟動mysql服務

可以添加系統變數:export PATH=/usr/local/mysql/bin/:$PATH
[plain] view plaincopyprint?01.[[email protected] ~]# service mysql start 
[[email protected] ~]# service mysql start

如果出現錯誤Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/iZ23i33p2ccZ.pid).等

則可查看日誌cat /usr/local/mysql/data/iZ23i33p2ccZ.err

執行/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data自動重新整理重啟下
 
測試mysql是否安裝成功

[plain] view plaincopyprint?01.[[email protected] ~]# /usr/local/mysql/bin/mysql -u root -p 
02.Enter password:  
03.Welcome to the MySQL monitor.  Commands end with ; or \g. 
04.Your MySQL connection id is 1 
05.Server version: 5.5.37 Source distribution 
06.  
07.Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved. 
08.  
09.Oracle is a registered trademark of OracleCorporation and/or its 
10.affiliates. Other names may be trademarksof their respective 
11.owners. 
12.  
13.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement. 
14.  
15.mysql> show databases; 
16.+--------------------+ 
17.| Database           | 
18.+--------------------+ 
19.| information_schema | 
20.| mysql              | 
21.| performance_schema | 
22.| test               | 
23.+--------------------+ 
24.4 rows in set (0.03 sec) 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.