ubuntu10.10,下載mysql源碼,編譯安裝

第一次在linux上安裝mysql,還是費了一些周折,總算基本理清思路了。

先說說我最終成功安裝的步驟,即:下載mysql源碼,編譯安裝 

 當前mysql版本是5.5.20,我的系統版本是ubuntu 10.10

1下載源碼:

     在官方網站,       選擇:MySQL Community Server--download     選擇 sourcecode,前面幾個都是什麼rpm,最後一個是我覺得應該下載的包:

Generic Linux (Architecture Independent), Compressed TAR Archive
5.5.20 23.2M
(mysql-5.5.20.tar.gz)
2下載完成,解壓縮。

裏面有個安裝說明文件:INSTALL-SOURCE

打開,裏面這一段是核心安裝步驟:(命令前都加sudo執行!)

# Preconfiguration setup     首先是添加一個用戶組
shell> groupadd mysql
shell> useradd -r -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz         解壓縮源碼包
shell> cd mysql-VERSION                          切換到源碼包目錄
shell> cmake .                                            執行cmake,產生mk文件(沒有cmake,sudo apt-get install cmake)
shell> make                                                 編輯
shell> make install                                       安裝
# End of source-build specific instructions             -----------ok,安裝完成了哦
# Postinstallation setup                                ----下面是配置mysql
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql     ---執行內部mysql安裝(參看紅線下方執行結果
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional                           --字面意思:下面這個命令可選
shell> cp support-files/my-medium.cnf /etc/my.cnf    複製mysql配置文件
shell> bin/mysqld_safe --user=mysql &                啓動數據庫
# Next command is optional                          --字面意思:下面這個命令可選
shell> cp support-files/mysql.server /etc/init.d/mysql.server   設置自啓動


按照這個就能完整安裝了

3安裝完並且配置完,進去看一下

在/usr/local/mysql 目錄,執行

root@cheng-laptop:/usr/local/mysql#  ./bin/mysql -u root -S /tmp/mysql.sock -p

正常登錄,提示:

Server version: 5.5.20-log Source distribution

Copyright (c) 2000, 2011, 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>

4官方網站有個gui工具,可以下載試一下:

MySQL Workbench (GUI Tool)

5其他就是創建鏈接或者環境變量,實現在終端中,直接執行mysql........

這個網上很多,自己蒐集吧

-------------------------------------------------------------------------------------------------------------

執行內部mysql安裝結果)

cheng@cheng-laptop:/usr/local/mysql$ sudo scripts/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

(要設置開機自啓動,請將文件複製到系統正確的地方)
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
(記得給mysql管理員設置密碼)
To do so, start the server, then issue the following commands:(設置密碼方式1)
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h cheng-laptop password 'new-password'
Alternatively you can run:(或者你可以運行下面這個命令進行密碼設置,我用的這個,裏面其實不只是設置root密碼)
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:(運行MySQL daemon,需要cd到當前目錄,執行./bin/mysqld_safe &)
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
cheng@cheng-laptop:/usr/local/mysql$ 

------------------------------------------------------------------------------------------------------

其他:

1關於ubuntu安裝版本,官網

》》》》》MySQL Community Server--Debian Linux ,

這裏有*.deb安裝包
A:ubuntu是Debain發展來的,應該是可以安裝的,至於是Debain 5還是Debain 6,我就說不清了。
B:我的ubuntu 10.10發行的時候,還沒有Debain 6,所以我應該是Debain 5。
C:當初嘗試的時候,Debain 6,Debain 5我都安裝過,安裝沒有報錯,因爲在系統菜單中沒有發現mysql快捷方式,以爲沒有安裝成功,現在想想應該是安裝成功了,只是我沒有進行配置,配置一下應該能用。

》》》》》》》還有一個版本應該也可以用:

MySQL Community Server--generic,最後一個

Linux - Generic 2.6 (x86, 64-bit), Compressed TAR Archive   5.5.20 177.3M
(mysql-5.5.20-linux2.6-x86_64.tar.gz)
這個版本網上有說,其實就是一個通用版本(二進制版本),下載下來不需要安裝,配置裏面有個配置文件“INSTALL-BINARY”,配置一下就能用了,很簡單。

》》》》》》其他的rpm包,是redhat用的,ubuntu安裝需要轉換成deb再安裝,個人不推薦這種方式

2 常見錯誤解決:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
剛開始的時候,被這個錯誤搞暈了,其實就是“連接文件”目錄不對應,mysqld.sock是一個連接配置文件
我看了一下我的文件在“/tmp/mysql.sock”
所以用-S指定連接文件就ok了
  ./bin/mysql -u root -S /tmp/mysql.sock -p



發佈了32 篇原創文章 · 獲贊 1 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章