yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison bison-devel
建議到官方網站下載http://dev.mysql.com/downloads/mysql/,選擇「Source Code」。下載的過程,須要註冊一個Oracle帳戶,若是有直接登陸就好mysql
提供一個下載地址:http://101.96.10.47/dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.14.tar.gzc++
新版本的源碼增長了boost庫,若是你下的源碼裏面沒有須要下載這個庫,不然會報錯sql
cd /usr/local/src wget http://101.96.10.47/dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.14.tar.gz tar -zvxf mysql-boost-5.7.14.tar.gz cd mysql-5.7.14
groupadd -r mysql useradd -r -g mysql mysql
mkdir -p /home/mysql/data mkdir -p /home/mysql/logs mkdir -p /home/mysql/temp
備註:真實的生產環境通常來講會獨立放在根目錄下,方便磁盤掛載上去數據庫
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/home/mysql/data \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DWITH_BOOST=./bootst/boost_1_59_0 \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DENABLE_DTRACE=0 \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DWITH_EMBEDDED_SERVER=1
備註:使用cmake源碼安裝MySQL,若是你打算安裝到不一樣的路徑,注意修改上面語句彙總的「/usr/local/mysql」和「/home/mysql/data」安全
配置解釋:socket
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //設置安裝目錄性能
-DMYSQL_DATADIR=/home/mysql/data //設置數據庫存放目錄 優化
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock //設置UNIX socket目錄網站
-DDEFAULT_CHARSET=utf8mb4 //設置默認字符集ui
-DDEFAULT_COLLATION=utf8mb4_general_ci //設置默認校對規則
-DWITH_INNOBASE_STORAGE_ENGINE=1 //添加InnoDB引擎支持
-DSYSCONFDIR=/etc //設置my.cnf配置文件的所在目錄,默認爲安裝目錄
make #編譯安裝的過程比較久,編譯安裝完成執行make install make install #安裝完成後清理一下零時文件 make clean
#拷貝可執行文件到指定的目錄下,並修更名字爲mysqld cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #授予可執行的權限 chmod +x /etc/init.d/mysqld #設置爲開機啓動 systemctl enable mysqld
chown -Rf mysql:mysql /usr/local/mysql chown -Rf mysql:mysql /home/mysql
#參考,具體裏面的參數說明,請自行晚上搜索 [mysqld] character-set-server = utf8mb4 collation-server = utf8mb4_general_ci skip-external-locking skip-name-resolve user = mysql port = 3306 basedir = /usr/local/mysql datadir = /home/mysql/data tmpdir = /home/mysql/temp # server_id = ..... socket = /usr/local/mysql/mysql.sock log-error = /home/mysql/logs/mysql_error.log pid-file = /home/mysql/data/mysql.pid open_files_limit = 10240 back_log = 600 max_connections=500 max_connect_errors = 6000 wait_timeout=605800 #open_tables = 600 #table_cache = 650 #opened_tables = 630 max_allowed_packet = 32M sort_buffer_size = 4M join_buffer_size = 4M thread_cache_size = 300 query_cache_type = 1 query_cache_size = 256M query_cache_limit = 2M query_cache_min_res_unit = 16k tmp_table_size = 256M max_heap_table_size = 256M key_buffer_size = 256M read_buffer_size = 1M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 64M lower_case_table_names=1 default-storage-engine = INNODB innodb_buffer_pool_size = 1G innodb_log_buffer_size = 32M innodb_log_file_size = 128M innodb_flush_method = O_DIRECT ##################### long_query_time= 2 slow-query-log = on slow-query-log-file = /home/mysql/logs/mysql-slow.log [mysqldump] quick max_allowed_packet = 32M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
vi /etc/profile #末尾添加如下內容 #mysql env export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib source /etc/profile
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
備註:
我用上面的語句執行後,好像沒起啥做用,而後把-datadir裏面的數據所有刪除,用之前的腳本執行了一次,而後成功
mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
[root@db-01 ~]# systemctl start mysqld [root@db-01 ~]# systemctl status mysqld ?.mysqld.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysqld) Active: active (running) since Sat 2016-08-27 18:02:31 CST; 9s ago Docs: man:systemd-sysv-generator(8) Process: 13086 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS) Process: 13211 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS) CGroup: /system.slice/mysqld.service ?..13228 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/home/mysql/data --pid-file=/home/mysql/data/mysql.pid ?..13878 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/home/mysql/data --plugin-dir=/usr/local/mysql/... Aug 27 18:02:29 db-01 systemd[1]: Starting LSB: start and stop MySQL... Aug 27 18:02:31 db-01 mysqld[13211]: Starting MySQL.. SUCCESS! Aug 27 18:02:31 db-01 systemd[1]: Started LSB: start and stop MySQL.
[root@db-01 ~]# ps -ef | grep mysql root 13228 1 0 18:02 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/home/mysql/data --pid-file=/home/mysql/data/mysql.pid mysql 13878 13228 0 18:02 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/home/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --open-files-limit=10240 --pid-file=/home/mysql/data/mysql.pid --socket=/usr/local/mysql/mysql.sock --port=3306 root 14266 14187 0 18:05 pts/0 00:00:00 grep --color=auto mysql
MySQL和Oracle數據庫同樣,數據庫也默認自帶了一個 root 用戶(這個和當前Linux主機上的root用戶是徹底不搭邊的),咱們在設置好MySQL數據庫的安全配置後初始化root用戶的密碼。配製過程當中,一路輸入 y 就好了。這裏只說明下MySQL5.7.14版本中,用戶密碼策略分紅低級 LOW 、中等 MEDIUM 和超強 STRONG 三種,推薦使用中等 MEDIUM 級別!
mysql_secure_installation
在這裏設置的root用戶明碼,能夠經過命令登錄,可是不能執行任何操做,須要重置密碼
mysql -u root -p #首次進入,沒法進行任何操做,會報錯,運行mysqladmin重置密碼 mysqladmin -u root
[root@db-01 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.14-log Source distribution 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | edu_demo | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
這樣MySQL 5.7.14就完成了安裝,若是想要從新安裝,只須要進入 /usr/local/src/mysql-5.7.14目錄,從新執行make install 就好。