一、RPM、Yum 的安裝方式:安裝方便、安裝速度快,沒法定製html
二、二進制:不須要安裝,解壓便可使用,不能定製功能mysql
三、編譯安裝:可定製,安裝慢。linux
編譯安裝中須要注意的是 5.5以前的編譯方式是:./configure make && make install sql
而5.5以後則使用:cmake數據庫
企業中使用的安裝方式:先編譯,而後製做rpm,製做yum庫,而後yum安裝。app
簡單、速度快、可定製,比較複雜 製做時間長ide
軟件包儘可能去官方網站下載優化
官方地址:https://www.mysql.com/網站
不一樣的安裝方式下載不一樣的包ui
Linux-Generic 表明的是二進制包
編譯安裝的話下載Source Code,表示源碼包
博主的安裝方式是編譯安裝方式,而二進制安裝方式,就是將下載的二進制包解壓後,便可
5.6與5.7的編譯安裝差別主要是初始化不一樣
5.7初始化完成後,會自動設置一個初始密碼,而5.6沒有
依賴包 yum install -y ncurses-devel libaio-devel 安裝cmake yum install cmake -y
useradd -s /sbin/nologin -M -u 999 mysql
最好指定好uid,對管理數據庫有好處
找到下載的mysql包所在路徑,而後進行解壓,軟件包儘可能去官方網站下載
tar zxf mysql-5.6.36.tar.gz
解壓完成後,使用 cd 進入解壓好的mysql目錄中,進行cmake
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36 \ -DMYSQL_DATADIR=/application/mysql-5.6.36/data \ -DMYSQL_UNIX_ADDR=/application/mysql-5.6.36/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITH_ZLIB=bundled \ -DWITH_SSL=bundled \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLE_DOWNLOADS=1 \ -DWITH_DEBUG=0
cmake安裝過程作了什麼呢?
(1)定製功能:存儲引擎、字符集、壓縮等
(2)定製安裝位置、數據存放位置、文件位置
make && make install
這兩步完成後而後建立軟鏈接,這樣在使用mysql的時候方便
ln -s /application/mysql-5.6.36/ /application/mysql
這步作的主要是指定mysql的管理用戶,程序路徑,數據存儲路徑
若是不設置管理用戶爲mysql會致使啓動報錯
對於mysql的 my.cnf 配置文件參數優化與解釋請參照:http://www.cnblogs.com/lyq863987322/p/8074749.html
\cp /application/mysql/support-files/my*.cnf /etc/my.cnf ### 將配置文件複製到/etc下,能夠不用複製 /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
chown -R mysql.mysql /application/mysql/
將啓動文件複製到/etc/init.d下,方便啓動關閉管理,並啓動
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld chmod 700 /etc/init.d/mysqld /etc/init.d/mysqld start
這一步就是對於博主這種比較懶得人有好處了,之後在登錄的時候就不用在將mysql的詳細路徑打一遍了
echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile --- 將mysql命令路徑添加到環境變量配置文件 tail -1 /etc/profile ----- 查看添加結果 source /etc/profile ----- 有結果了,執行這一步讓環境變量生效 echo $PATH --- 不放心能夠再檢查一下生效了沒有
mysql ----- 這樣就能夠直接登錄了
這樣mysql5.6就已經安裝完成了,默認的登錄是沒有密碼
設置/修改密碼:
mysqladmin -u root password '123456' mysql -uroot -p123456
tar xf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
而且設置軟鏈接
mv mysql-5.7.17-linux-glibc2.5-x86_64 /application/mysql-5.7.17
ln -s /application/mysql-5.7.17 /application/mysql
useradd -s /sbin/nologin -M -u 999 mysql chown -R mysql.mysql /application/mysql-5.7.17
/application/mysql-5.7.17/bin/mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.17 --datadir=/application/mysql-5.7.17/data
執行初始化的輸出信息:最後一行有初始密碼,必定要先記住
2017-12-20T08:08:00.604818Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-12-20T08:08:03.828187Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-12-20T08:08:04.164378Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-12-20T08:08:04.389472Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e7a07703-e55c-11e7-b24e-000c29c5641d. 2017-12-20T08:08:04.391108Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-12-20T08:08:04.827938Z 1 [Note] A temporary password is generated for root@localhost: *:vQq%O:E6dD
對於mysql的 my.cnf 配置文件參數優化與解釋請參照:http://www.cnblogs.com/lyq863987322/p/8074749.html
cp /application/mysql-5.7.17/support-files/my-default.cnf /etc/my.cnf cp /application/mysql-5.7.17/support-files/mysql.server /etc/init.d/mysqld
由於啓動文件中指定的mysql程序路徑與安裝路徑不一樣,因此須要改過來
sed 's#/usr/local#/application#g' /application/mysql-5.7.17/bin/mysqld_safe /etc/init.d/mysqld -i
echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile tail -1 /etc/profile source /etc/profile echo $PATH
[root@baba tools]# mysqladmin -uroot -p password '123456' Enter password: mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. [root@baba tools]# mysql -uroot -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.17 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
安裝完成