您好,登錄后才能下訂單哦!
下面講講關于CentOS6.x/CentOS7.x系統環境一鍵實現安裝mysql5.方法,文字的奧妙在于貼近主題相關。所以,閑話就不談了,我們直接看下文吧,相信看完CentOS6.x/CentOS7.x系統環境一鍵實現安裝mysql5.方法這篇文章你一定會有所受益。
一、系統環境及說明
系統:CentOS6.x_x64 mysql:社區版5.6.21,開源數據庫用的最多的mysql,編譯安裝比較繁瑣,yum安裝版本比較低且默認安裝的位置是/var/下,本次采用官方下載的rpm包,通過腳本自動化安裝并定制數據目錄到獨立分區中(本次為/data1目錄)
另外補充部分是給出針對Ubuntu/CentOS7的實際配置;最后提供了腳本一鍵安裝;注意的是glibc版本要大于2.12
二、準備安裝包
1、官方下載
#https://dev.mysql.com/downloads/mysql/5.6.html#downloads 選擇對應的版本和平臺軟件包:
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.rpm
2、本實驗用到的包
http://pan.baidu.com/s/1nvn0nUx包含了以下軟件包(也是從官方下載):
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
三、安裝mysql5.6
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、本實驗腳本如下:
將以上rpm包放到一個目錄,創建my.cnf文件(公供參考)
cat my.cnf
[mysqld] # GENERAL # user = mysql default-storage-engine = InnoDB socket = /data1/mysqldb/data/mysql.sock pid-file = /data1/mysqldb/data/mysql.pid # MyISAM # key-buffer-size = 32M myisam-recover = FORCE,BACKUP # SAFETY # max-allowed-packet = 16M max-connect-errors = 1000000 # DATA STORAGE # datadir = /data1/mysqldb/data # BINARY LOGGING # log-bin = /data1/mysqldb/log/mysql-bin expire-logs-days = 14 sync-binlog = 1 # CACHES AND LIMITS # tmp-table-size = 32M max-heap-table-size = 32M query-cache-type = 0 query-cache-size = 0 max-connections = 500 thread-cache-size = 50 open-files-limit = 65535 table-definition-cache = 1024 table-open-cache = 2048 # INNODB # innodb-flush-method = O_DIRECT innodb-log-files-in-group = 2 innodb-log-file-size = 64M innodb-flush-log-at-trx-commit = 1 innodb-file-per-table = 1 innodb-buffer-pool-size = 256M # LOGGING # log-error = /data1/mysqldb/log/mysql-error.log log-queries-not-using-indexes = 0 slow-query-log = 1 slow-query-log-file = /data1/mysqldb/log/mysql-slow.log
注意:生產環境有些優化參數請按需修改;以上僅供參考;您也可以到https://tools.percona.com/ 網站填寫相關參數生成配置文件;
并在目錄中創建一個install.sh腳本內容如下:
cat install.sh
#!/bin/bash src_dir=$(pwd) cd $src_dir 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 /data1/mysqldb/data ] || mkdir -p /data1/mysqldb/data [ -d /data1/mysqldb/log ] || mkdir -p /data1/mysqldb/log chown mysql.mysql /data1/mysqldb -R cd $src_dir cp ${src_dir}/my.cnf /etc cd /usr/bin ./mysql_install_db --user=mysql --basedir=/usr --datadir=/data1/mysqldb/data #遷移數據目錄到/data1/mysqldb/data下可自行定制 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 /data1/mysqldb/data/mysql.sock /var/lib/mysql/mysql.sock #由于一些mysql工具默認到這里找mysql.sock所以做個軟鏈
四、注意問題
1、關閉selinux否則腳本安裝不成功
2、安裝后系統自帶的postfix和crontab工具被御了,重新yum安裝 一次即可
3、mysql服務的root密碼為空,請自行修改root密碼
或在腳本中添加以下行 在mysql遷移好目錄啟動后自動修改mysql root密碼
mysqladmin -u root password "123.com"
補充部分:
CentOS7.x安裝 mysql 5.7.21
到mysql官方下載Linux通用包wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
解壓:
#yum install libaio1 numactl -y #tar -xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local #ln -sv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
添加環境變量
cat /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH
初始化:
#useradd -r mysql #mkdir -pv /data/mysql #chown mysql.mysql /data/mysql #mysqld --initialize-insecure --datadir=/data/mysql --user=mysql --basedir=/usr/local/mysql/ #mkdir /usr/local/mysql/etc/my.cnf.d #chown mysql.mysql -R /usr/local/mysql/etc #cp /etc/my.cnf /usr/local/mysql/etc/ #cat /usr/local/mysql/etc/my.cnf
[mysqld] datadir=/data/mysql socket=/tmp/mysql.sock [mysqld_safe] log-error=/usr/local/mysql/log/error.log pid-file=/var/run/mysql/mysql.pid !includedir /usr/local/mysql/etc/my.cnf.d
復制啟動腳本:
#cp /usr/local/mysql/suppor-files/mysql.server /etc/init.d/mysqld #touch /usr/local/mysql/log/error.log #chwon mysql.mysql /usr/local/mysql/log/error.log #chmod 755 /usr/local/mysql/log/error.log #chkconfig --add mysqld #chkconfig mysqld on #service mysqld start
Ubuntu 16.04上安裝
下載同樣的包
安裝的步驟與上面CentOS7類似,不同的是ubuntu 16.04上不支持service 方式管理
因此需要復制
#apt-get install libaio1 numactl ## 安裝依賴包 #cp /usr/local/mysql/suppor-files/mysql.server /etc/init.d/mysqld #sudo systemctl daemon-reload #chown root.mysql /usr/local/mysql -R #chmod 775 /usr/local/mysql -R #systemctl enable mysqld #systemctl start mysqld #systemctl status mysqld
如圖:
mysql -uroot -p
如圖:
注意安裝后mysql root密碼為空;請自行設置 root密碼;以下腳本一鍵安裝亦是如此!
一鍵安裝腳本
以上在CentOS7上安裝和Ubuntu 16.04下安裝大同小異,均可以安裝成功;因此整理成一鍵安裝腳本!
#cat auto_install_mysql.sh
#!/bin/bash #version 2018-04-01 by san setenforce 0 yum install wget -y sourceDir=$(pwd) installDir=/usr/local mysqlData=/data1/mysqldb mysqlBaseDir=/usr/local/mysql mysqldb="mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz" xtrabackup="percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm" check_mariadb(){ if [ $(rpm -qa|grep mariadb|wc -l) -gt 1 ] then echo "Find mariadb installed!" read -t 6 -p "default y|Y remove pause 6 seconds!n|N Cacle install!" yesNo if [[ $yesNo == "n" || $yesNo == "N" ]] then echo "Cacle install mysqldb" && exit 0 else yum -y remove mariadb mariadb-server rm -rf /etc/my.cnf fi fi } check_mariadb [ -f $sourceDir ]||mkdir $sourceDir -pv [[ $(id mysql >/dev/null && echo $?) == 0 ]] && echo "mysql is exsits!" || useradd -r mysql cd $sourceDir [ -f ${sourceDir}/${mysqldb} ] || wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz tar -xvf $mysqldb -C $installDir cd $installDir ln -sv mysql-5.7.21-linux-glibc2.12-x86_64 mysql [ -f /etc/profile.d/mysql.sh ]|| echo "export PATH=$mysqlBaseDir/bin:$PATH" >/etc/profile.d/mysql.sh source /etc/profile.d/mysql.sh #創建mysql數據目錄 [ -d $mysqlData ]|| mkdir -pv $mysqlData chown mysql.mysql $mysqlData $mysqlBaseDir/bin/mysqld --initialize-insecure --datadir=$mysqlData --user=mysql --basedir=$mysqlBaseDir/ [ -d $mysqlBaseDir/etc/my.cnf.d ] || mkdir -pv $mysqlBaseDir/etc/my.cnf.d [ -d $mysqlBaseDir/log ] || mkdir -pv $mysqlBaseDir/log echo ' [mysqld] datadir=/data1/mysqldb socket=/data1/mysqldb/mysql.sock key_buffer_size = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 query_cache_limit = 1M query_cache_size = 64M query_cache_type = 1 symbolic-links=0 #binlog server-id = 1 log_bin = /data1/mysqldb/mysql-bin.log #建議打開 innodb_file_per_table=ON skip_name_resolve=ON [mysqld_safe] log-error=/usr/local/mysql/log/error.log pid-file=/var/run/mysql/mysql.pid !includedir /usr/local/mysql/etc/my.cnf.d ' >/$mysqlBaseDir/etc/my.cnf touch /usr/local/mysql/log/error.log chown mysql.mysql $mysqlBaseDir/* -R chown mysql.mysql /usr/local/mysql/etc/my.cnf.d -R #add manager script cp -rp $mysqlBaseDir/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on systemctl daemon-reload service mysqld start ln -sv /data1/mysqldb/mysql.sock /tmp/mysql.sock ### echo "mysql root password is empty" echo 'install xtrabackup tool' cd $sourceDir [ -f ${sourceDir}/${xtrabackup} ] || wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.8/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm yum install ./percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm -y
補充:
python pip install MySQL-python 時報錯
mysql_config 找不到問題
# ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config
以及error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
ubuntu 執行如下命令
sudo apt-get install python-dev \
build-essential libssl-dev libffi-dev \
libxml2-dev libxslt1-dev zlib1g-dev \
對于以上CentOS6.x/CentOS7.x系統環境一鍵實現安裝mysql5.方法相關內容,大家還有什么不明白的地方嗎?或者想要了解更多相關,可以繼續關注我們的行業資訊板塊。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。