這個blog绪穆,我們來聊聊MySQL 8.0在CENTOS 7 環(huán)境下的安裝
Linux先安裝MySQL的方法有多種:
1.倉庫安裝(yum,apt,zypper)
2.二進(jìn)制包安裝(rpm,deb)
3.docker安裝
4.壓縮包解壓安裝
5.編譯安裝
這里我們選擇最后一種,編譯安裝。
一.下載軟件
二.環(huán)境準(zhǔn)備
1.安裝所需的基本的包
yum -y install ntpdate gcc gcc-c++ ncurses ncurses-devel cmake readline-devel zlib.x86_64 zlib-devel.x86_64 bison libcurl-* net-tool* tree nmap sysstat lrzsz dos2unix telnet.x86_64 nethogs iftop iotop unzip ftp.x86_64 xfs* expect vim wget psmisc openssh-client* libaio libaio1 libnuma openssl-devel bzip2
2.檢查系統(tǒng)是否已經(jīng)安裝了mysql
centos 7開始默認(rèn)安裝的是mariadb了,存在的話污朽,先卸載
-- 檢查是否已經(jīng)安裝mysql
[root@**** ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@**** ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
[root@**** ~]#
3.關(guān)掉防火墻和SElinux
systemctl stop firewalld
systemctl disabled firewalld
systemctl stop postfix
systemctl disable postfix
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config && cat /etc/selinux/config >> ${tmplog_dir}/base.log 2>&1
setenforce 0
getenforce
4.升級gcc
-- 升級比較慢拦耐,需要耐心等待
mkdir /usr/local/tools && cd /usr/local/tools
wget http://mirrors.nju.edu.cn/gnu/gcc/gcc-5.5.0//gcc-5.5.0.tar.xz
tar xf gcc-5.5.0.tar.xz
cd gcc-5.5.0
./contrib/download_prerequisites
mkdir build && cd build
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make && make install
5.升級cmake
cd /usr/local/tools
wget https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.Z
tar -xvf cmake-3.14.5.tar.Z
cd cmake-3.14.5/
./bootstrap
make && make install
如果出現(xiàn)以下錯誤
ibstdc++.so.6: version `CXXABI_3.4.20' not found (required by ./destructor)
處理如下:
find / -name "libstdc++.so*"
mv /usr/lib64/libstdc++.so.6.0.19 /tmp/
cp /usr/local/tools/gcc-5.5.0/build/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.21 /usr/lib64/
mv /usr/lib64/libstdc++.so.6 /tmp/
cd /usr/lib64/
ln -s libstdc++.so.6.0.21 libstdc++.so.6
6.創(chuàng)建用戶及目錄
-- 創(chuàng)建用戶
groupadd mysql
useradd -d /home/mysql -g mysql -m mysql
passwd mysql
-- 創(chuàng)建目錄
mkdir -p /u01/my3306/data
mkdir -p /u01/my3306/log/iblog
mkdir -p /u01/my3306/log/binlog
mkdir -p /u01/my3306/run
mkdir -p /u01/my3306/tmp
-- 授權(quán)
chown -R mysql:mysql /u01/my3306
chmod -R 755 /u01/my3306
7.配MySQL環(huán)境變量
su - mysql
vi .bash_profile
PATH :/u01/my3306/bin
source .bash_profile
8.上傳并解壓文件
tar -zxvf mysql-boost-8.0.20.tar.gz -C /usr/local
三.安裝
-- 上一步解壓的位置
cd /usr/local/mysql-8.0.20
--cmake編譯安裝
cmake . \
-DWITH_BOOST=/usr/local/mysql-8.0.20/boost/boost_1_70_0 \
-DCMAKE_INSTALL_PREFIX=/u01/my3306 \
-DMYSQL_DATADIR=/u01/my3306/data \
-DWITHOUT_CSV_STORAGE_ENGINE=1 \
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \
-DWITHOUT_ARCHIVE_STORAGE_ENGINE=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_SSL=system \
-DCMAKE_CXX_COMPILER=/usr/local/bin/g++ \
-DCMAKE_C_COMPILER=/usr/local/bin/gcc
make -j 8 && make install
四.配置文件及初始化
配置文件:
路徑:/u01/my3306/my.cnf
[client]
port=3306
socket=/u01/my3306/mysql.sock
[mysql]
pid_file=/u01/my3306/run/mysqld.pid
[mysqld]
basedir = /u01/my3306
datadir = /u01/my3306/data
port = 3306
socket = /u01/my3306/mysql.sock
#必填項
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#binlog
log_bin=/u01/my3306/log/binlog/binlog
binlog_format=row
expire_logs_days=7
log_slave_updates=ON
sync_binlog=100
#logging
log_error=/u01/my3306/log/error.log
slow_query_log_file=/u01/my3306/log/slow.log
log_queries_not_using_indexes=0
slow_query_log=1
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1
初始化:
chown -R mysql:mysql /u01/my3306
chown -R mysql:mysql /usr/local/mysql-8.0.20
su - mysql
/usr/local/mysql-8.0.20/bin/mysqld --basedir=/u01/my3306 --initialize --datadir=/u01/my3306/data --user=mysql
生成的臨時密碼一定要保留,后面登陸需要使用
[10:36:47] [mysql@*** data]$ /usr/local/mysql-8.0.20/bin/mysqld --basedir=/u01/my3306 --initialize --datadir=/u01/my3306/data --user=mysql
[10:36:47] 2020-05-29T02:36:59.773440Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
[10:36:47] 2020-05-29T02:36:59.773474Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
[10:36:47] 2020-05-29T02:36:59.774430Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.20/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 27145
[10:36:47] 2020-05-29T02:36:59.790675Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
[10:36:48] 2020-05-29T02:37:00.416071Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
[10:36:50] 2020-05-29T02:37:01.867872Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: eIzp%ZzE-3Rs
檢查data目錄文件是否已生成
[mysql@**** ~]$ /usr/local/mysql-8.0.20/bin/mysqld --defaults-file=/u01/my3306/my.cnf --initialize --datadir=/u01/my3306/data --user=mysql
[mysql@*** ~]$ cd /u01/my3306/data/
[mysql@*** data]$ ll
total 45040
-rw-r----- 1 mysql mysql 56 May 28 22:07 auto.cnf
-rw------- 1 mysql mysql 1676 May 28 22:07 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 May 28 22:07 ca.pem
-rw-r--r-- 1 mysql mysql 1112 May 28 22:07 client-cert.pem
-rw------- 1 mysql mysql 1676 May 28 22:07 client-key.pem
-rw-r----- 1 mysql mysql 491520 May 28 22:07 #ib_16384_0.dblwr
-rw-r----- 1 mysql mysql 8880128 May 28 22:07 #ib_16384_1.dblwr
drwxr-x--- 2 mysql mysql 6 May 28 22:07 #innodb_temp
drwxr-x--- 2 mysql mysql 6 May 28 22:07 mysql
-rw-r----- 1 mysql mysql 15728640 May 28 22:07 mysql.ibd
drwxr-x--- 2 mysql mysql 8192 May 28 22:07 performance_schema
-rw------- 1 mysql mysql 1676 May 28 22:07 private_key.pem
-rw-r--r-- 1 mysql mysql 452 May 28 22:07 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 May 28 22:07 server-cert.pem
-rw------- 1 mysql mysql 1676 May 28 22:07 server-key.pem
-rw-r----- 1 mysql mysql 10485760 May 28 22:07 undo_001
-rw-r----- 1 mysql mysql 10485760 May 28 22:07 undo_002
五.MySQL啟動和登陸
啟動MySQL
mysqld_safe --defaults-file=/u01/my3306/my.cnf --user=mysql &
修改密碼:
-- 這個地方的密碼是第四步生成的臨時密碼孔轴,必須修改了才能正常使用mysql
[mysql@*** my3306]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20 Source distribution
Copyright (c) 2000, 2020, 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>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'test';
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
六.FAQ
1.gcc、cmake下載較慢
軟件下載較慢碎捺,可以通過其它途徑下載路鹰,然后傳到服務(wù)器即可
2.初始化密碼忘記保存
刪除數(shù)據(jù)文件后重新初始化
cd /u01/my3306/data/
rm -rf *
/usr/local/mysql-8.0.20/bin/mysqld --basedir=/u01/my3306 --initialize --datadir=/u01/my3306/data --user=mysql
3.Can't connect to local MySQL server through socket '/tmp/mysql.sock'
登陸的時候報錯,/tmp/mysql.sock不存在收厨,創(chuàng)建軟鏈接即可
ln -s /u01/my3306/mysql.sock /tmp/mysql.sock
4.啟動報錯
啟動報錯晋柱,多半是my.cnf配置錯誤,查看指定的errlog進(jìn)行排查
more /u01/my3306/log/error.log