在CentOS7.4上手動編譯安裝Mysql-5.7.20

實驗環境:
CentOS 7.4mysql

mysql軟件: mysql-boost-5.7.20.tar.gzc++

1.安裝編譯工具sql

yum -y install \
ncurses \
ncurses-devel \
bison \
cmake\
gcc \
gcc-c++ \
make數據庫

2.解壓包socket

tar xf mysql-boost-5.7.20.tar.gz工具

3.定製配置spa

cd mysql-5.7.20/server

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \                     //5.7版本必須添加這個參數
-DWITH_SYSTEMD=1ci

4.編譯並安裝it

make && make install

5.添加程序賬戶,並相關設置

useradd -s /sbin/nologin  mysql

chown -R mysql:mysql /usr/local/mysql/

chown mysql:mysql /etc/my.cnf

6.修改配置文件

vi /etc/my.cnf

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

 

7.設置環境變量

echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile                //把這兩個路徑添加到環境變量中,並放到profile文件中使之開機自運行,不然不生效

echo 'export PATH' >> /etc/profile                                                       //把PATH設爲全局變量

source /etc/profile

 

8.初始化數據庫

cd /usr/local/mysql/

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

 

9.添加到systemctl系統服務

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

systemctl daemon-reload

systemctl start mysqld

netstat -anpt | grep 3306

systemctl enable mysqld

 

10.Mysql設置賬戶和密碼,默認無密碼

mysqladmin -u root -p password "abc123"

mysql -u root -p 

相關文章
相關標籤/搜索