Centos 7 源碼編譯安裝mysql 5.6.22(整理篇)

來源:互聯網
上載者:User

標籤:mysql linux

 經過看了幾篇文檔,都沒有寫完全。稍微整理了一下,重新一步一步進行編譯安裝mysql在centos7上。


安裝步驟如下:

1、安裝編譯環境

# yum -y install gcc- gcc-c++  ncurses-devel per

# yum install cmake

2、建立mysql目錄和帳號,及目錄屬性

# mkdir -p /data/mydata

# mkdir -p /usr/local/mysql

# useradd -d /data/mydata -s  /sbin/nologin -g mysql mysql

# cd data/mydata/

# chown -R mysql:mysql .

# cd /usr/local/mysql/

# chown -R mysql:mysql .

3、下載copy到系統裡

# cd

# ls

anaconda-ks.cfg  mysql-5.6.22.tar.gz

4、解壓mysql源碼包

# tar -zxvf mysql-5.6.22.tar.g

5、編譯mysql源碼包

說明:從mysql5.5起,mysql源碼安裝開始使用cmake了,設定源碼編譯配置指令碼。

-DCMAKE_INSTALL_PREFIX=dir_name

設定mysql安裝目錄

-DMYSQL_UNIX_ADDR=file_name

設定監聽通訊端路徑,這必須是一個絕對路徑名。預設為/tmp/mysql.sock

-DDEFAULT_CHARSET=charset_name

設定伺服器的字元集。
 預設情況下,MySQL使用latin1的(CP1252西歐)字元集。cmake/character_setsNaNake檔案包含允許的字元集名稱列表。

-DDEFAULT_COLLATION=collation_name

設定伺服器的定序。

-DWITH_INNOBASE_STORAGE_ENGINE=1 
 -DWITH_ARCHIVE_STORAGE_ENGINE=1
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 
 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1

儲存引擎選項:
 
 MyISAM,MERGE,MEMORY,和CSV引擎是預設編譯到伺服器中,並不需要明確地安裝。
 
 靜態編譯一個儲存引擎到伺服器,使用-DWITH_engine_STORAGE_ENGINE= 1
 
 可用的儲存引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB),  PARTITION (partitioning support), 和PERFSCHEMA  (Performance Schema)

-DMYSQL_DATADIR=dir_name

設定mysql資料庫檔案目錄

-DMYSQL_TCP_PORT=port_num

設定mysql伺服器監聽連接埠,預設為3306

-DENABLE_DOWNLOADS=bool

是否要下載可選的檔案。例如,啟用此選項(設定為1),cmake將下載Google所使用的測試套件運行單元測試。

# cd mysql-5.6.22

# cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=mysql.mysql  -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWIT

H_ARCHIVE_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mydata  -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1

[[email protected] mysql-5.6.22]# make

[[email protected] mysql-5.6.22]# make  install

6、初始化mysql資料庫

# cd scripts/

# ls

mysql_install_db

# ./mysql_install_db --user=mysql  --datadir=/data/mydata

FATAL ERROR: please install the following  Perl modules before executing ./mysql_install_db:

Data::Dumper

初始化過程中會報錯,需要安裝perl-Module-Install.noarch

# yum install -y  perl-Module-Install.noarch

# scripts/mysql_install_db --user=mysql  --datadir=/data/mydata

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 !

To do so, start the server, then issue  the following commands:

 

   ./bin/mysqladmin -u root password ‘new-password‘

   ./bin/mysqladmin -u root -h localhost.localdomain password  ‘new-password‘

 

Alternatively you can run:

 

   ./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:

 

   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 at  http://bugs.mysql.com/

 

The latest information about MySQL is  available on the web at

 

   http://www.mysql.com

 

Support MySQL by buying support/licenses  at http://shop.mysql.com

 

New default config file was created as  ./my.cnf and

will be used by default by the server  when you start it.

You may edit this file to change server  settings

7、複製mysql服務和開機檔案

# cp  /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

# cp  /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

 

8、開啟mysqld服務

[[email protected] ~]# service mysqld start

Starting MySQL. SUCCESS!

9、添加到chkconfig裡

[[email protected] ~]# chkconfig

[[email protected] ~]# chkconfig --add  mysqld

[[email protected] ~]# chkconfig --list

iprdump           0:off 1:off 2:on 3:on 4:on 5:on 6:off

iprinit                0:off 1:off 2:on 3:on 4:on 5:on 6:off

iprupdate           0:off 1:off 2:on 3:on 4:on 5:on 6:off

mysqld            0:off 1:off 2:on 3:on 4:on 5:on 6:off

netconsole          0:off 1:off 2:off 3:off 4:off 5:off 6:off

network           0:off 1:off 2:on 3:on 4:on 5:on 6:off

檢查連接埠

[[email protected] ~]# netstat -tulnp | grep  3306

tcp6        0      0 :::3306                 :::*                    LISTEN 

21466/mysqld 

10、設定環境變數PATH路徑

[[email protected] /]# vi /etc/profile

-- INSERT --

 

PATH=/usr/local/mysql/bin:$PATH

export PATH

:wq

"/etc/profile"

# source /etc/profile

11、進入資料庫報錯

[[email protected] /]# mysql -uroot

ERROR 2002 (HY000): Can‘t connect to  local MySQL server through socket ‘mysql.mysql‘ (2)

12、編輯my.cnf

[[email protected] ~]# vi /etc/my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/data/mydata

port=3306

socket=/data/mydata/mysql.sock

server_id=1

[mysqld_safe]

log-error=/data/log/mysqld.log

 [mysql]

socket=/data/mydata/mysql.sock

[mysqldump]

socket=/data/mydata/mysql.sock

[mysqladmin]

socket=/data/mydata/mysql.sock

13、重啟mysqld服務

# etc/init.d/mysqld restart

14、進入資料庫並設定密碼

# mysql –uroot

mysql> set password = password(‘123456‘);

Query OK, 0 rows affected (0.00 sec)

mysql> quit

Bye

 

到這裡資料庫安裝就完成了


感謝各位大拿的blog。參考連結

http://www.aiezu.com/db/mysql_cant_connect_through_socket.html

http://blog.csdn.net/xiagege3/article/details/41852895

http://blog.csdn.net/hengrjgc/article/details/40299213

http://wilr.iteye.com/blog/2168659

http://www.cnblogs.com/xiongpq/p/3384681.html

http://msnvip.iteye.com/blog/542004

http://blog.sina.com.cn/s/blog_637e04c9010117ri.html

http://www.cnblogs.com/fuhj02/p/3541173.html


本文出自 “程子” 部落格,請務必保留此出處http://jif521.blog.51cto.com/848361/1597899

Centos 7 源碼編譯安裝mysql 5.6.22(整理篇)

聯繫我們

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