一、系統及安裝說明html
系統:CentOS6.x_x64 mysql
mysql:社區版5.6.21,開源數據庫用的最多的mysql,編譯安裝比較繁瑣,yum安裝版本比較低且默認安裝的位置是/var/下,本次採用官方下載的rpm包,經過腳本自動化安裝並定製數據目錄到獨立分區中(本次爲/data目錄)web
二、準備安裝包sql
1>官方下載數據庫
#https://dev.mysql.com/downloads/mysql/5.6.html#downloads 選擇對應的版本和平臺軟件包:bash
MySQL-shared-compat-5.6.x-1.el6.x86_64.rpm #x就是你下的版本號如下類同
MySQL-devel-5.6.x-1.el6.x86_64.rpm
MySQL-shared-5.6.x-1.el6.x86_64.rpm
MySQL-client-5.6.x-1.el6.x86_64.rpm
MySQL-test-5.6.x-1.el6.x86_64.rpm
MySQL-server-5.6.x-1.el6.x86_64.rpmdom
2>本實驗用到的包ide
https://pan.baidu.com/s/1kVraS8R 密碼: iybx工具
包含了如下軟件包:spa
MySQL-shared-compat-5.6.21-1.el6.x86_64.rpm
MySQL-devel-5.6.21-1.el6.x86_64.rpm
MySQL-shared-5.6.21-1.el6.x86_64.rpm
MySQL-client-5.6.21-1.el6.x86_64.rpm
MySQL-test-5.6.21-1.el6.x86_64.rpm
MySQL-server-5.6.21-1.el6.x86_64.rpm
2>mysql數據庫默認的一些主要目錄:
一、數據庫目錄 /var/lib/mysql/
二、配置文件 /usr/share/mysql(mysql.server命令及配置文件)
三、相關命令 /usr/bin (mysqladmin mysqldump等命令)
四、啓動腳本 /etc/rc.d/init.d/(啓動腳本文件mysql的目錄)
五、修改配置文件位置 cp /usr/share/mysql/my-default.cnf /etc/my.cnf
三、安裝
1>若是是官方下載的請直接執行下面操做
#rpm -ivh MySQL-shared-compat-5.6.x-1.el6.x86_64.rpm #提供基礎依賴組件,須要第一個安裝 #yum remove mysql-libs -y #御載默認自帶的mysql-lib #yum install libaio -y #安裝libiao #rpm -ivh MySQL-devel-5.6.x-1.el6.x86_64.rpm #rpm -ivh MySQL-shared-5.6.x-1.el6.x86_64.rpm #rpm -ivh MySQL-client-5.6.x-1.el6.x86_64.rpm #rpm -ivh MySQL-test-5.6.x-1.el6.x86_64.rpm #rpm -ivh MySQL-server-5.6.x-1.el6.x86_64.rpm
說明:以上直接安裝的數據目錄在
/var/lib/mysql
下,你也能夠自定義數據目錄在一個分區(磁盤)上
所以可經過腳本從新初始化安裝到別的目錄;完成自定製;
2>腳本執行
#!/bin/bash src_dir=$(pwd) cd $src_dir tar xvf mysql5.6.21.x86_64.rpms.tar.gz tar xvf mysql5.6.21.x86_64.rpms.tar cd mysql5.6.21 rpm -ivh MySQL-shared-compat-5.6.21-1.el6.x86_64.rpm yum remove mysql-libs -y yum install libaio -y rpm -ivh MySQL-devel-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-shared-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-client-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-test-5.6.21-1.el6.x86_64.rpm rpm -ivh MySQL-server-5.6.21-1.el6.x86_64.rpm #service mysql start && echo "mysql5.6.21 has installes sucess!" #mysql_root_pwd=`gawk -F : '{ print $4 }' /root/.mysql_secret` #echo "A random root password has been set. You will find it in '/root/.mysql_secret'." #echo "The random root password was:'${mysql_root_pwd// }'" service mysql stop [ -d /data/mysqldb/data ] || mkdir -p /data/mysqldb/data [ -d /data/mysqldb/log ] || mkdir -p /data/mysqldb/log chown mysql.mysql /data/mysqldb -R cd /usr/bin ./mysql_install_db --user=mysql --basedir=/usr --datadir=/data/mysqldb/data #遷移數據目錄到/data/mysqldb/data下可自行定製 cd $src_dir cp ${src_dir}/my.cnf /etc cd /var/lib mv mysql /tmp mkdir mysql chown mysql.mysql mysql service mysql start && echo "Mysql root password was empty.Please change when you login mysql." ln -s /data/mysqldb/data/mysql.sock /var/lib/mysql/mysql.sock #因爲一些mysql工具默認到這裏找mysql.sock因此作個軟鏈 四、注意事項 mysql服務的root密碼爲空,請自行修改root密碼。或在腳本中添加如下行 在mysql遷移好目錄啓動後自動修改mysql root密碼 |
mysqladmin -u root password "123456"