MySQL5.6的Linux安裝之二進位安裝(一)

來源:互聯網
上載者:User

標籤:adl   shutdown   state   show   tor   buffer   libc   ict   pts   

最近在寫一個MySQL的shell安裝指令碼

說明一點著裡面的所有路徑都是絕對路徑

下面來總結一下安裝 遇到的一些問題,以及安裝的過程

這個是內建的安裝過程

shell> groupadd mysqlshell> useradd -r -g mysql mysqlshell> cd /usr/localshell> tar zxvf /path/to/mysql-VERSION-OS.tar.gzshell> ln -s full-path-to-mysql-VERSION-OS mysqlshell> cd mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell> scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysql datashell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server

安裝之前首先檢查有沒有mysql的進程,如果有我們還安裝個啥

mysqlProcessNum=`/bin/ps aux | /bin/grep mysql | /usr/bin/wc -l | /bin/awk ‘{ print $1 }‘`;if [ $mysqlProcessNum -gt 3 ]; then    echo "已經安裝MySQL"
exit
fi

然後下載(可以從官網下載,但是個人感覺太慢了,於是就搭建了一個簡單的ftp伺服器,當然也可以本地上傳嘛,在這裡我就不細說了)

# download mysql packageyum install libaio   #MySQL的一個依賴包/usr/bin/yum install awk wget -ymysqlDownloadURL=ftp://。。。。。。。。。/pub/mysql/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz;cd /tmp;/bin/rm -rf mysql*.tar.gz/usr/bin/wget $mysqlDownloadURL;

好我們已經下載好了

下面開始進入正題

解壓,建立軟串連

packageName=`/bin/ls | /bin/grep mysql*.tar.gz`;# unpakcage mysql/bin/tar zxvf $packageName -C /usr/localmysqlAllNameDir=`/bin/ls -l /usr/local | grep mysql | /bin/awk ‘{ print $9 }‘`/bin/ln -s $mysqlAllNameDir /usr/local/mysql

添加使用者和使用者組(判斷一下,如果沒添加就添加一下)

userNum=`/bin/cat /etc/passwd | /bin/grep mysql | /bin/awk -F ‘:‘ ‘{ print $1 }‘ | /usr/bin/wc -l`if [ $userNum -lt 1 ];then    /usr/sbin/groupadd mysql    /usr/sbin/useradd -d /usr/local/mysql -s /sbin/nologin -g mysql mysql    echo "成功添加"fi

檢查/etc下面是否有my.cnf檔案,有的話就幹掉,或者備份

/bin/mv /etc/my.cnf /etc/my.cnf.bak

下面初始化

/usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/data --user=mysql --basedir=/usr/local/mysql

說明一點!!!修改許可權一定要在初始化之後,否則初始化之後的data目錄不一定被附有許可權

/bin/chown -R root.mysql /usr/local/mysql

/bin/chown -R mysql.mysql /usr/local/mysql/data/

現在可以自己寫一個設定檔放在/etc下面

/etc/my.cnf (這裡也說明一點,MySQL設定檔有參數替換原則)

順序是這樣的

/etc/my.cnf      /etc/mysql/my.cnf        /usr/local/mysql/etc/my.cnf         ~/.my.cnf

[client]socket=/usr/local/mysql/mysql-files/mysql.sock[mysqld]explicit_defaults_for_timestamp=truedatadir=/usr/local/mysql/datasocket=/usr/local/mysql/mysql-files/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# LOGslow_query_log = 1slow_query_log_file = /usr/local/mysql/mysql-files/mysql-slow.loglong_query_time = 2# GENERAL LOG#general_log = 1#general_log_file = /usr/local/mysql/mysql-files/mysql-general.log# BINARY LOGserver_id=101log_bin=/usr/local/mysql/mysql-files/mysql-bin.logbinlog_format=ROWsync_binlog=1expire_logs_days=7# ERROR LOGlog_error=/usr/local/mysql/mysql-files/mysql.err# OTHERcharacter_set_server = utf8mb4transaction-isolation = READ-COMMITTEDmax_connections = 1000log-queries-not-using-indexeslog_throttle_queries_not_using_indexes = 10# INNODBinnodb_strict_mode=1innodb_file_format=Barracudainnodb_file_format_max=Barracudainnodb_read_io_threads=4innodb_write_io_threads=8 # 8 ~ 12innodb_io_capacity=1000 # HDD:800 ~ 1200 SSD: 10000+innodb_adaptive_flushing=1 # SSD: 0innodb_flush_log_at_trx_commit=1innodb_max_dirty_pages_pct=75innodb_buffer_pool_dump_at_shutdown=1innodb_buffer_pool_load_at_startup=1innodb_flush_neighbors=1 # SSD:0innodb_log_file_size=1024M # SSD:4G~8G HDD:1G~2Ginnodb_purge_threads=1 # SSD:4innodb_lock_wait_timeout=3innodb_print_all_deadlocks=1pid-file=/usr/local/mysql/data/mysqld/mysqld.pid[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/usr/local/mysql/data/mysqld/mysqld.pid

下面以mysql_safe方式啟動

/usr/local/mysql/bin/mysqld_safe &

好下面啟動mysqld

/usr/local/mysql/bin/mysqld restart

[[email protected] mysql]# ./bin/mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.25-log MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.00 sec)mysql> 

 

說明幾點:

1.刪除重新安裝的時候一定要看看是不是mysqld 的進程全部殺死了(ps -ef|grep mysqld),如果有使用“kill -9  進程號”殺死不然會嚴重影響下次安裝

2.可能是第二次在機器上安裝mysql,有殘餘資料影響了服務的啟動。去mysql的資料目錄/data看看,如果存在mysql-bin.index,就刪除掉

其他要說明的我在之前的安裝過程中已經說明了

下面就是安裝指令碼的基本過程

#!/bin/bash# mysql install script, the home directory is /usr/local/mysql-VERSION and the soft link is /usr/local/mysqlyum install libaio/usr/bin/yum install awk wget -yconfig=`/bin/pwd`mysqlProcessNum=`/bin/ps aux | /bin/grep mysql | /usr/bin/wc -l | /bin/awk ‘{ print $1 }‘`;if [ $mysqlProcessNum -gt 3 ]; then    echo "已經安裝MySQL"fi# download mysql packagemysqlDownloadURL=ftp://222.26.224.236/pub/mysql/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz;cd /tmp;/bin/rm -rf mysql*.tar.gz/usr/bin/wget $mysqlDownloadURL;packageName=`/bin/ls | /bin/grep mysql*.tar.gz`;# unpakcage mysql/bin/tar zxvf $packageName -C /usr/localmysqlAllNameDir=`/bin/ls -l /usr/local | grep mysql | /bin/awk ‘{ print $9 }‘`/bin/ln -s $mysqlAllNameDir /usr/local/mysqluserNum=`/bin/cat /etc/passwd | /bin/grep mysql | /bin/awk -F ‘:‘ ‘{ print $1 }‘ | /usr/bin/wc -l`if [ $userNum -lt 1 ];then    /usr/sbin/groupadd mysql    /usr/sbin/useradd -d /usr/local/mysql -s /sbin/nologin -g mysql mysql    echo "成功添加"fi
#/bin/mv /etc/my.cnf /etc/my.cnf.bak
/usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/data --user=mysql --basedir=/usr/local/mysql/bin/chown -R root.mysql /usr/local/mysql/bin/chown -R mysql.mysql /usr/local/mysql/data/
#我的設定檔放到root目錄下面了

/bin/cp $config/my.cnf /etc/    

/usr/local/mysql/bin/mysqld_safe &
#/bin/chown -R mysql.mysql /usr/local/mysql/data/#/bin/cp $config/my.cnf /etc/#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld#chmod 755 /etc/init.d/mysqld

 

祝成功

MySQL5.6的Linux安裝之二進位安裝(一)

聯繫我們

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