1. 程式人生 > 實用技巧 >MySQL-8.0.21安裝

MySQL-8.0.21安裝

1.安裝依賴

yum install -y ncurses-devel libaio-devel glibc autoconf openssl openssl-devel

2.安裝cmake

cd 
wget https://github.com/Kitware/CMake/releases/download/v3.19.0-rc3/cmake-3.19.0-rc3-Linux-x86_64.sh
sh cmake-3.19.0-rc3-Linux-x86_64.sh
# 一路回車 兩個y
mv cmake-3.19.0-rc3-Linux-x86_64 /usr/local/

新增環境變數並生效

cat >> /etc/profile <<'EOF'
PATH=$PATH:/usr/local/cmake-3.19.0-rc3-Linux-x86_64/bin
EOF
source /etc/profile

3.安裝c++ cc

#新增scl源 下載編譯工具
yum install centos-release-scl scl-utils-build -y
yum install devtoolset-7-gcc.x86_64 devtoolset-7-gcc-c++.x86_64 devtoolset-7-gcc-gdb-plugin.x86_64 -y

#切換環境
scl enable devtoolset-7 bash
gcc -v

rm -rf /usr/bin/{c++,cc}

ln -s /opt/rh/devtoolset-7/root/usr/bin/c++ /usr/bin/c++ 
ln -s /opt/rh/devtoolset-7/root/usr/bin/cc /usr/bin/cc

4.下載解壓

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.21.tar.gz
mkdir -p /data/mysql
mkdir -p /usr/local/mysql
tar -zxf mysql-boost-8.0.21.tar.gz -C /usr/local

5.生成

cd /usr/local/mysql-8.0.21
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.21/boost -DFORCE_INSOURCE_BUILD=1

6.修改程式碼

vim  ./extra/libedit/libedit-20190324-3.1/src/terminal.c
 		/*char buf[TC_BUFSIZE];*/  # 註釋掉
        char *area;
        const struct termcapstr *t;
        sigset_t oset, nset;
        int lins, cols;

        (void) sigemptyset(&nset);
        (void) sigaddset(&nset, SIGWINCH);
        (void) sigprocmask(SIG_BLOCK, &nset, &oset);

        area = NULL;  # 改為NULL

7.編譯安裝

make && make install

8.配置MySQL

cat >> /etc/profile <<'EOF'
PATH=$PATH:/usr/local/mysql/bin
EOF
source /etc/profile

useradd mysql -s /sbin/nologin -M

cd /usr/local/mysql/
mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data --initialize    # 記住結尾的密碼

vim /etc/my.cnf
[mysqld]
datadir=/data/mysql/data
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/data/mysql/data/mysql.log
pid-file=/data/mysql/data/mysql.pid


vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

systemctl daemon-reload 

9.啟動MySQL

systemctl start mysql

10.修改密碼 (必須)

mysqladmin -uroot -p預設密碼 password 你要的密碼