您好,登錄后才能下訂單哦!
**mysql5.7.20源碼部署
作者:mj培根(mjboy)**
1)安裝基礎包
yum install -y gcc gcc-c++ automake autoconf git make
yum -y install cmake bison-devel ncurses-devel libaio-devel
2)創建目錄(用于存放下載文件)
mkdir -p /home/mjboy/tools
下載mysql5.7.20至此/home/mjboy/tools目錄
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.20.tar.gz
wget https://downloads.mysql.com/archives/get/file/mysql-boost-5.7.20.tar.gz
3)創建mysql用戶:
groupadd -g 800 mysql
useradd -u 800 mysql -s /sbin/nologin -M -g mysql
4)tar解壓包
tar xf mysql-5.7.20.tar.gz
tar xf mysql-boost-5.7.20.tar.gz
5)cmake配置編譯選項
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.20 \
-DMYSQL_DATADIR=/application/mysql-5.7.20/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.7.20/tmp/mysql.sock \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/home/mjboy/tools/mysql-5.7.20/boost \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_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_MYISAM_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
注意:utf8mb4是utf8的超集,但一般utf8夠用了,而且utf8mb4會消耗更多空間
參數具體含義:
參考官方文檔--cmake mysql5.7參考
https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
6)編譯 && 安裝
make && make install
7)設置mysql軟鏈接
ln -s /application/mysql-5.7.20/ /application/mysql
思考:為什么要設置軟鏈接--(版本更換,提供便利)
8)拷貝啟動文件及配置文件(如果沒有,則自己創建,最好自己制作my.cnf)
cp /application/mysql-5.7.20/support-files/mysql.server /etc/init.d/mysqld
#配置my.cnf
cp /application/mysql-5.7.20/support-files/my-default.cnf /etc/my.cnf
[root@mysql57 ~]# cat /etc/my.cnf
[client]
port = 3306
socket = /application/mysql/data/tmp/mysql.sock
#這個配置段設置啟動MySQL服務的條件;在這種情況下,no-auto-rehash確保這個服務啟動得比較快。
#no-auto-rehash
[server]
user = root
port = 3306
socket = /application/mysql/data/tmp/mysql.sock
basedir = /application/mysql
datadir = /application/mysql/data/
9)設置環境變量
[root@master data]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@master data]# tail -1 /etc/profile
[root@master data]# export PATH=/application/mysql/bin:$PATH
[root@master data]# source /etc/profile
[root@master data]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
注意:為什么要把application的環境變量放在前面?
http://oldboy.blog.51cto.com/2561410/1122867(環境變量位置先后的影響)
10)授權
chown -R mysql:mysql /application/mysql/data/
chmod -R 1777 /tmp/
11)初始化
/application/mysql-5.7.20/bin/mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.20/ --datadir=/application/mysql-5.7.20/data
#初始密碼記錄下來
#A temporary password is generated for root@localhost: NphU.;4Xdl#w
12)創建mysql.sock存放目錄,并授權
mkdir /application/mysql-5.7.20/tmp
chown -R mysql.mysql /application/mysql-5.7.20/
13)啟動
/etc/init.d/mysqld start或者systemctl start mysqld
14)修改初始密碼
mysqladmin -uroot -p'NphU.;4Xdl#w' password 'root'
15)登錄mysql成功!
[root@mysql57 ~]# mysql -uroot -proot -e "select version();show databases;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 5.7.20 |
+-----------+
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| tmp |
+--------------------+
[root@mysql57 ~]#
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。