Centos mini 6.5安裝MySQL5.6.4
成都創(chuàng)新互聯(lián)公司專注于贛榆企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站開發(fā)。贛榆網(wǎng)站建設(shè)公司,為贛榆等地區(qū)提供建站服務(wù)。全流程按需開發(fā),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
1.下載安裝包
云盤地址:http://pan.baidu.com/s/1bpsgXUf
安裝需要包工具
yum -y install wget vim lrzsz tar
2.更換yum源(個(gè)人在yum裝有些包出問題就換阿里云的yum源了)
這里更換為阿里云yum源
cd /etc/yum.repos.d/
mv CentOS-Bose.repo CentOS-Bose.repo.bak
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
Yum makecache
3.創(chuàng)建mysql用戶
useradd mysql //已經(jīng)有的不需要?jiǎng)?chuàng)建
4.卸載原來的mysql rpm包
rpm -qa|grep mysql //查詢是否有相關(guān)包
Yum -y remove *mysql* //我這里用yum卸載的
5.關(guān)閉防火墻,關(guān)閉selinux
Service iptables stop //個(gè)人習(xí)慣性關(guān)閉防火墻
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
6.安裝所需依賴包
yum -y install make gcc gcc-c++ gcc-gfortran flexbison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devellibpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devellibxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devellibevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogse2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-develgettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof
7.安裝cmake
Mysql5.6版本后需要cmake來配置編譯
tar -zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./configure
gmake && gmake install
8.開始安裝mysql
tar -zxvf mysql-5.6.4-m7.tar.gz
cd mysql-5.6.4-m7
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-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
============================================******************************************==========================================================================================================================================================================
單實(shí)例的的安裝操作
9.安裝完相關(guān)操作
修改mysql安裝目錄權(quán)限
Chmod +w /usr/local/msyql
Chown -R msyql.msyql /usr/local/mysql
//在啟動(dòng)MySQL服務(wù)時(shí),會按照一定次序搜索my.cnf,先在/etc目錄下找,找不到則會搜索”$basedir/my.cnf”就是安裝目錄下/usr/local/mysql/my.cnf,這是新版MySQL的配置文件的默認(rèn)位置!注意:在CentOS 6.x版操作系統(tǒng)的最小安裝完成后,在/etc目錄下會存在一個(gè)my.cnf,需要將此文件更名為其他的名字。如:/etc/my.cnf.bak,否則,該文件會干擾源碼安裝的MySQL的正確配置,造成無法啟動(dòng)。由于我們已經(jīng)卸載了最小安裝完成后的mysq庫所以,就沒必要操作了。
cd support-files/
如果還有my.cnf請備份
mv /etc/my.cnf /etc/my.cnf.bak
復(fù)制配置文件到etc下
cp my-medium.cnf /etc/my.cnf
//執(zhí)行初始化配置腳本,創(chuàng)建系統(tǒng)自帶的數(shù)據(jù)庫和表,注意配置文件的路徑
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
//拷貝mysql安裝目錄下support-files服務(wù)腳本到init.d目錄
#拷貝腳本
cp support-files/mysql.server /etc/init.d/mysqld
#賦予權(quán)限
chmod +x /etc/init.d/mysqld
#設(shè)置開機(jī)啟動(dòng)
chkconfig mysqld on
#啟動(dòng)MySQL
service mysqld start 或者 /etc/init.d/mysql start
MySQL5.6.x啟動(dòng)成功后,root默認(rèn)沒有密碼,我們需要設(shè)置root密碼。設(shè)置之前,我們需要先設(shè)置PATH,要不,不能直接調(diào)用mysql
修改/etc/profile文件
vim /etc/profile
在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
#讓配置立即生效
source /etc/profile
#登陸測試,默認(rèn)是沒有密碼,直接回車就可進(jìn)入
mysql -uroot -p
設(shè)置mysqlroot用戶密碼
mysqladmin -u root password "newpass"
#如果root已經(jīng)設(shè)置過密碼,采用如下方法
mysqladmin -u root password oldpass "newpass"
#驗(yàn)證mysql安裝路徑
ls -ld /usr/local/mysql/
多實(shí)例的安裝
接著上面源碼包安裝完成開始
1,創(chuàng)建多實(shí)例數(shù)據(jù)庫文件夾
mkdir -pv/usr/local/mysql/data/{3306,3307,3308}
chown -Rmysql.mysql /usr/local/mysql/data/
2,初始化數(shù)據(jù)庫
cd/usr/local/mysql
scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3306/
scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3307/
scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3308/
3,準(zhǔn)備配置文件#提供多配置文件模板
cd bin
./mysqld_multi--example > /usr/local/mysql/data/multi.cnf
4,修改模板文件 (不用的注釋掉)
vim /usr/local/mysql/data/multi.cnf
[mysqld_multi]cd
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin =/usr/local/mysql/bin/mysqladmin
user = root
#password = root #設(shè)置了密碼后一定要開啟,不然命令停止會有問題 (三個(gè)實(shí)例數(shù)據(jù)庫密碼一樣)
[mysqld1]
socket = /tmp/mysql.sock1
port = 3306
pid-file = /usr/local/mysql/data/3306/mysql.pid
datadir = /usr/local/mysql/data/3306/
[mysqld2]
socket = /tmp/mysql.sock2
port = 3307
pid-file = /usr/local/mysql/data/3307/mysql.pid
datadir = /usr/local/mysql/data/3307/
#language = /usr/local/mysql/share/mysql/english
#user = unix_user1
[mysqld3]
#mysqld = /path/to/mysqld_safe
#ledir = /path/to/mysqld-binary/
#mysqladmin =/path/to/mysqladmin
socket = /tmp/mysql.sock3
port = 3308
pid-file = /usr/local/mysql/data/3308/mysql.pid
datadir = /usr/local/mysql/data/3308/
#language = /usr/local/mysql/share/mysql/swedish
#user = unix_user2
5,修改/etc/profile文件
vim /etc/profile
在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
#讓配置立即生效
source /etc/profile
6,啟動(dòng)msyql數(shù)據(jù)庫
mysqld_multi--defaults-file=/usr/local/mysql/data/multi.cnf start 1,2,3
查看端口狀態(tài)
netstat -anpt|grep mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 25470/mysqld
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 25476/mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 25453/mysqld
7,設(shè)置mysql密碼
mysqladmin-uroot -S /tmp/mysql.sock1 password "root"
mysqladmin-uroot -S /tmp/mysql.sock2 password "root"
mysqladmin-uroot -S /tmp/mysql.sock3 password "root"
8,進(jìn)入數(shù)據(jù)庫
Mysql -S/tmp/mysql.sock1 -proot
9,關(guān)閉數(shù)據(jù)庫3種方法。
mysqladmin -S/tmp/mysql.sock1 shutdown -proot
mysqld_multi--defaults-file=/usr/local/mysql/data/multi.cnf stop 1,2,3