編譯安裝mysql

一、mysql簡介  

MySQL是一個開放源碼的小型關聯式數據庫管理系統,開發者爲瑞典MySQL AB公司,之後經歷SUN公司收購MySQL AB,Orance 公司收購SUM,所以目前mysql項目由Orance公司負責運營和維護。MySQL被廣泛地應用在Internet上的中小型網站中。由於其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,許多中小型網站爲了降低網站總體擁有成本而選擇了MySQL作爲網站數據庫。

二、源碼編譯及安裝

(1)創建運行用戶

[root@localhost ~]# useradd -M -u 50 -s /sbin/nologin mysql


(2)解包

官方下載站點http://www.mysql.com

 在此我用的 mysql-5.1.55版本

[root@localhost ~]# tar xf mysql-5.1.55.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/mysql-5.1.55/

[root@localhost mysql-5.1.55]#


(3)配置

[root@localhost mysql-5.1.55]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312

上述配置中 各選項的含義

>  --prefix:  將指定mysql數據庫程序安裝到哪個目錄,如/usr/local/mysql

>  --with-charset:  指定默認使用的字符集編碼,應與校隊規則相對應,如utf8

>  --with-collation:   指定默認使用的字符集校隊規則

>   --with-extra-charsets:  指定額外支持的其他字符集編碼,如gbk,gb232等


注:要進行一些小調整,才能編譯後獲得完整的支持,如修改include子文件下的config.h文件,添加相應編譯定義即可(默認存在,若不存在添加即可)

[root@localhost mysql-5.1.55]# vim include/config.h  

#define HAVE_CHARSET_gbk 1  

#define HAVE_CHARSET_gb2312 1    


(4)編譯安裝

[root@localhost mysql-5.1.55]# make && make install


三、其他調整

(1)建立配置文件

[root@localhost mysql-5.1.55]# cp support-files/my-medium.cnf /etc/my.cnf


(2)初始化數據庫

[root@localhost mysql-5.1.55]# cd /usr/local/mysql/bin/

[root@localhost bin]# ./mysql_install_db --user=mysql [--datadir=/mydata/data]  

[root@localhost bin]# chown -R root:mysql /usr/local/mysql/

[root@localhost bin]# chown -R mysql /usr/local/mysql/var/


(3)優化執行路徑,程序庫路徑

[root@localhost bin]# ln -s /usr/local/mysql/bin/*  /usr/local/bin/

[root@localhost bin]# ln -s /usr/local/mysql/lib/mysql/*  /usr/lib/

[root@localhost bin]# ln -s /usr/local/mysql/include/mysql/*  /usr/include/


(4)添加系統服務

[root@localhost bin]# cd /usr/src/mysql-5.1.55/

[root@localhost mysql-5.1.55]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql-5.1.55]# chmod +x /etc/init.d/mysqld 

[root@localhost mysql-5.1.55]# chkconfig --add mysqld

[root@localhost mysql-5.1.55]# /etc/init.d/mysqld start

[root@localhost mysql-5.1.55]# /etc/init.d/mysqld status


(5)啓動mysql,成功

[root@localhost ~]# service mysqld restart

Shutting down MySQL.                                 [確定]

Starting MySQL.                                            [確定]


(6)初始設置密碼

[root@localhost ~]# mysqladmin -u root password 123456


(7)進入mysql數據庫

[root@localhost ~]# mysql -u root -p123456

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.1.55-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help.

Type '\c' to clear the current input statement.

mysql>


此時已經完成了mysql的搭建,接下來會在介紹mysql語句。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章