《Mysql應用linux下mysql 5.5.8 源碼編譯安裝》要點:
本文介紹了Mysql應用linux下mysql 5.5.8 源碼編譯安裝,希望對您有用。如果有疑問,可以聯(lián)系我們。
本節(jié)內(nèi)容:
linux下mysql 5.5.8 源碼編譯安裝.MYSQL必讀
系統(tǒng):ubuntu 10.10
mysql源碼文件:mysql-5.5.8.tar.gz
安裝所需工具:cmake, gnu make, gcc, perl, libncurses5-dev, bison(可選), chkconfig
注:
1.官方2010-11-18的源碼有幾處bug,在編譯之前參照官方的說明,進行了手動修改.MYSQL必讀
官方說明鏈接:http://lists.mysql.com/commits/126782
2.官方5.5版本參考手冊:http://dev.mysql.com/doc/
汗了一下,3392頁的參考手冊!
=>工具安裝:
1. cmake
----沒有自己編譯安裝cmake
----shell:~$ sudo apt-get install cmake
----版本:2.8.2
2. gnu make
----ubuntu自帶
----版本:3.81
3.gcc
----ubuntu自帶
----版本:4.4.5(官方文檔:必須3.2以上)
4.perl
----ubuntu自帶
----版本:5.10.1
5.libncurses5-dev (ncurses-devel)
----若差了這個包,在cmake的時候會報錯.
----debian/ubuntu上的包名是libncurses5-dev,redhat和其他版本對應的是ncurses-devel
----shell:~$ sudo apt-get install libncurses5-dev
----報錯信息
------------------www.linuxidc.com---------------
-- mysql 5.5.8
-- 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,MYSQL必讀
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:256 (mysql_check_readline)MYSQL必讀
-- configuring incomplete, errors occurred!
---------------------------------
6. bison
----shell:~$ sudo apt-get install bison
----可選.沒有這個工具,在make的時候報出警告.
----警告記錄:
---------------------------------MYSQL必讀
warning: bison executables not found in path
---------------------------------
7.chkconfig
----后面配置mysql服務自啟動的時候需要.
----shell:~$ sudo apt-get install chkconfig
=>mysql安裝:
1.解壓源代碼文件
----shell定位到源代碼文件所在目錄
----解壓
shell:~$ tar zxvf mysql-5.5.8.tar.gz
2.cmake操作
----shell定位到解壓出的源代碼文件夾目錄(文件夾:mysql-5.5.8)
----cmake執(zhí)行:
---------------------------------
shell:~$ cmake -dcmake_install_prefix=/usr/local/mysql
-dmysql_datadir=/home/system_username/programming/mysql/mysqldata
-dsysconfdir=/etc
-dwith_innobase_storage_engine=1
-dwith_archive_storage_engine=1
-dwith_blackhole_storage_engine=1
-dwith_federated_storage_engine=1
-dwith_partition_storage_engine=1
-dmysql_unix_addr=/tmp/mysqld.sock
-dmysql_tcp_port=3306
-denabled_local_infile=1
-dextra_charsets=all
-ddefault_charset=utf8
-ddefault_collation=utf8-general_ci
-dmysql_user=mysql
注:沒有換行.官方文檔上,cmake 命令后面加個點不懂什么意思.在這里加上命令執(zhí)行不了
---------------------------------
源代碼配置選項說明:
//mysql安裝的主目錄,5.5.8版本默認為/usr/local/mysql,所以可以不添加
-dcmake_install_prefix=/usr/local/mysqlMYSQL必讀
//mysql數(shù)據(jù)保存的路徑,自定義
-dmysql_datadir=/home/system_username/mysql/mysqldataMYSQL必讀
//mysql配置文件地址------the default my.cnf option file directory
-dsysconfdir=/etcMYSQL必讀
//compile storage engine xxx statically into server
/*storage engines are built as plugins. you can build a plugin as a static module (compiled into the server)
*or a dynamic module (built as a dynamic library that must be installed into the server using the install
*plugin statement or the --plugin-load option before it can be used). some plugins might not support static
*or dynamic building.
*/
-dwith_innobase_storage_engine=1
-dwith_archive_storage_engine=1
-dwith_blackhole_storage_engine=1
-dwith_federated_storage_engine=1
-dwith_partition_storage_engine=1MYSQL必讀
//unix socket file
/*
*the unix socket file path on which the server listens for socket connections. this must be an absolute path
*name. the default is /tmp/mysql.sock
*/
-dmysql_unix_addr=/tmp/mysqld.sockMYSQL必讀
//數(shù)據(jù)庫服務器tcp/ip連接的監(jiān)聽端口,默認為3306
-dmysql_tcp_port=3306MYSQL必讀
//whether to enable local capability in the client library for load data infile
//默認為關閉,這里開啟
-denabled_local_infile=1MYSQL必讀
//數(shù)據(jù)庫編碼設置
-dextra_charsets=all
-ddefault_charset=utf8
-ddefault_collation=utf8-general_ci
3.編譯和安裝
----shell定位到源代碼文件夾目錄
----執(zhí)行:(編譯用了大概20分鐘)
shell:~$ make
shell:~$ make installMYSQL必讀
4.后續(xù)配置
----進入mysql安裝目錄下的腳本目錄
shell:~$ cd /usr/local/mysql/scripts
----利用mysql_install_db腳本生成新的mysql 授權表
./mysql_install_db --basedir=/usr/local/mysql --datadir=/home/system_username/programming/mysql/mysqldata
--user=mysql
----進入mysql安裝目錄下的支持文件目錄
shell:~$ cd /usr/local/mysql/support-files
----復制mysql配置文件
shell:~$ sudo cp my-medium.cnf /etc/my.cnfMYSQL必讀
----復制服務文件并修改
shell:~$ sudo cp mysql.server mysqld
----修改mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
mv mysqld /etc/init.d/mysqld
----啟動服務
shell:~$ service mysqld start
----關閉服務
shell:~$ service mysqld stop
---------------------------------
service命令:
1. 用于管理linux系統(tǒng)中服務的命令
2. 作用是去/etc/init.d目錄下尋找相應的服務,進行開啟和關閉等操作
3. 上述操作后,mysqld服務文件對應mysql.server文件
---------------------------------
----添加服務到自啟動項
shell:~$ sudo chkconfig --level 3 mysqld onMYSQL必讀
----設置軟連接使mysql, mysqldump, mysqladmin這三個命令能在shell中直接運行
shell:~$ sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
shell:~$ sudo ln -s /usr/local/mysql/bin/mysqldump /usr/bin
shell:~$ sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
---------------------------------
=>mysql數(shù)據(jù)庫中文亂碼解決 :
1. 亂碼分析
----從終端shell進入mysql
shell:~$ mysql
............
............
mysql> show variables like '%character%'
----得到以下數(shù)據(jù)庫編碼信息表:
+----------------------------------- +-------------------------------------------+
| variable_name | value |
+------------------------------------+-------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/charsets/ |
+------------------------------------ +-------------------------------------------+
可以看出character_set_database ,character_set_server 的編碼還是默認的latin1.
不知道為什么,之前default_charset設置成為utf8的,好像沒起作用.查看官方文檔
發(fā)現(xiàn),character_set_database不支持配置文件(/etc/my.cnf)變量設置,
但是character_set_server 支持配置文件變量設置.MYSQL必讀
2. 解決方法
----打開配置文件
shell:~$ sudo gedit /etc/my.cnf
然后在[mysqld]配置選項下添加
character-set-server = utf8
----然后進入mysql
執(zhí)行:
mysql> show variables like '%character%'
結果:character_set_database ,character_set_server兩項都變?yōu)閡tf8了
----測試:
往數(shù)據(jù)庫表中插入中文字段,中文就正常顯示了.MYSQL必讀
注:1.用5.1版本的時候如下辦法是可以解決中文編碼問題的
----在配置文件[mysqld]和[client]節(jié)下分別添加: default-character-set = utf8
2.不知到是不是手動編譯的原因,在5.5.8中配置文件中用上述辦法會造成數(shù)據(jù)庫服務無法啟動.
----錯誤日志如下:( datadir/username.err為錯誤日志文件)
----------------------------------------------------
mysqld_safe mysqld from pid file /home/cyberwym/programming/mysql/mysqldata/cyberwym.pid ended
...........
...........
[error] /usr/local/mysql/bin/mysqld: unknown variable 'default-character-set=utf8'
[error] aborting
----------------------------------------------------
----這樣會造成pid文件(datadir/username.pid)無法更新
----在配置文件[mysqld]和[client]節(jié)下分別去掉: default-character-set = utf8 后,數(shù)據(jù)庫服務就啟動正常了
CentOS 6.3下源碼編譯安裝MySQL 5.6
CentOS 6.5編譯安裝Percona 5.6.15(步驟)
centos6.4編譯安裝mysql5.5及Sphinx引擎的辦法詳解
mysql編譯安裝及多實例安裝的辦法分享
fedroa中編譯安裝mysql5.5的實例參考
安裝mysql5.5時只編譯客戶端
新編譯的MySQL無法通過service啟動的解決辦法
查看已安裝的mysql編譯參數(shù)的辦法MYSQL必讀
維易PHP培訓學院每天發(fā)布《Mysql應用linux下mysql 5.5.8 源碼編譯安裝》等實戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/7448.html