這篇文章主要介紹了centos編譯安裝mysql 5.6及安裝多個mysql實例詳解,需要的朋友可以參考下
--1.為mysql新建群組和用戶
# useradd -M -s /sbin/nologin mysql
--2.安裝需要的函式庫,編譯器
# yum install ncurses-devel openssl-devel cmake -y
--3.解壓縮
# tar zxvf mysql-5.6.35.tar.gz # cd mysql-5.6.35
--4.編譯安裝
# cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_USER=mysql \ -DWITH_DEBUG=0 \ -DWITH_SSL=system # make # make install
--5.拷貝模版,作為設定檔
# cp support-files/my-default.cnf /etc/my.cnf
--6.設定mysql權限
# chown -R mysql.mysql /usr/local/mysql/
--7.初始化mysql資料庫
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql # chown -R root /usr/local/mysql/ # chown -R mysql /usr/local/mysql/data/
--8.設定mysql開機自啟動
# cp support-files/mysql.server /etc/init.d/mysqld # chmod +x /etc/init.d/mysqld # chkconfig mysqld on
--9.測試並執行mysql
#service mysqld start
--10.修改mysql管理員密碼
#/usr/local/mysql/bin/mysqladmin -u root password '要设置的密码'
--11.使用使用者登入mysql
# /usr/local/mysql/bin/mysql -u root -p
--12.加入環境變數
# echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile # source /etc/profile
# CentOS 6.5最小化編譯安裝mysql 5.5.35設定多重實例
1、關閉防火牆
##1 2、關閉selinux
1234567 [root@mysql ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@mysql ~]# chkconfig iptables off
[root@mysql ~]# chkconfig iptables --list
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
12 [root@mysql ~]# setenforce 0 [root@mysql ~]# vim /etc/sysconfig/selinux
3、安裝mysql依賴套件及編譯工具;
#SELINUX=disabled 12 [root@mysql ~]# getenforce Permissive
4.1、安裝路徑:
1234 [root@mysql ~]# yum install libaio-devel -y [root@mysql ~]# yum install -y ncurses-devel [root@mysql ~]# yum install -y gcc gcc-c++ [root@mysql ~]# yum install -y cmake
4.2、資料庫路徑:
1 [root@mysql ~]# mkdir /usr/local/mysql
4.3、創建使用者和使用者群組1 [root@mysql ~]# mkdir /data/mysql -p
12 [root@mysql ~]# groupadd mysql [root@mysql ~]# useradd -r -g mysql -s /bin/false mysql
1 [root@mysql ~]# chown mysql:mysql -R /data/mysql
6、建立多實例資料庫檔案存放位置;1234567 [root@mysql ~]# yum install -y lrzsz
root@mysql ~]# mkdir /package
[root@mysql ~]# cd /package/
[root@mysql package]# tar xf mysql-5.5.32.tar.gz
[root@mysql package]# cd mysql-5.5.32
[root@mysql mysql-5.5.32]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/data/mysql/
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
[root@mysql mysql-5.5.32]# make && make install
12345678 [root@mysql ~]# mkdir -p /data/{3306,3307}/data [root@mysql ~]# tree /data /data |-- 3306 | `-- data `-- 3307 `-- data 4 directories, 0 files
注意:初始化資料庫時需要指定不同的資料目錄
123456789 [root@mysql 3306]# vim my.cnf [client] port = 3306 socket = /data/3306/mysql.sock [mysqld] port = 3306 socket = /data/3306/mysql.sock datadir = /data/3306 server-id = 3306
9、啟動多實例,啟動腳本可以加入到開機自啟動檔案。 123 [root@mysql mysql-5.5.32]# cd /usr/local/mysql/
[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306
[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307
12 [root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 >/dev/null & [root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 >/dev/null &
10、登入多實例資料庫
12345678 [root@mysql mysql]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 11621/mysqld tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1266/sshd tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11338/mysqld tcp 0 0 :::22 :::* LISTEN 1266/sshd udp 0 0 0.0.0.0:68 0.0.0.0:* 969/dhclient
12 [root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3306 -S /data/3306/mysql.sock [root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3307 -S /data/3307/mysql.sock
以上是詳細介紹centos編譯安裝mysql5.6及安裝多個mysql的範例程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!