當(dāng)前位置:首頁(yè) > IT技術(shù) > 系統(tǒng)服務(wù) > 正文

Linux第十周
2022-03-06 18:01:52

2、通過(guò)編譯、二進(jìn)制安裝MySQL5.7

?二進(jìn)制安裝MYSQL5.7?

#創(chuàng)建目錄并進(jìn)入
mkdir /server/
cd /server
#上傳剛下載的5.7的二進(jìn)制包
[root@centos8-2 server]# ll
total 650940
-rw-r--r-- 1 root root 666559924 Jan 25 10:18 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
#解包
tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
#做軟鏈接
[root@centos8-2 server]# ln -s mysql-5.7.36-linux-glibc2.12-x86_64 /server/mysql
[root@centos8-2 server]# ll
total 650940
lrwxrwxrwx 1 root root 35 Jan 26 10:49 mysql -> mysql-5.7.36-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root 129 Jan 26 10:48 mysql-5.7.36-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 666559924 Jan 25 10:18 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
#創(chuàng)建用戶
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
#設(shè)置環(huán)境變量并執(zhí)行
[root@centos8-2 server]# vim /etc/profile.d/mysql.sh
export PATH=/server/mysql/bin:$PATH
source /etc/profile
#授權(quán)和創(chuàng)數(shù)據(jù)目錄
chown -R mysql.mysql /server/*
mkdir /data/mysql/data -p
chown -R mysql.mysql /data
#安裝依賴
[root@centos8-2 server]# yum install -y libaio-devel
初始化
# 5.6 版本 初始化命令 /application/mysql/scripts/mysql_install_db
# 5.7跳過(guò)密碼初始化
[root@centos8-2 server]# mysqld --initialize-insecure --user=mysql --basedir=/server/mysql --datadir=/data/mysql/data
2022-01-26T02:57:10.811504Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-01-26T02:57:10.938434Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-01-26T02:57:10.960969Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-01-26T02:57:11.016304Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a82719f7-7e53-11ec-8563-000c29ffc567.
2022-01-26T02:57:11.018223Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-01-26T02:57:11.872502Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-01-26T02:57:11.872527Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-01-26T02:57:11.872974Z 0 [Warning] CA certificate ca.pem is self signed.
2022-01-26T02:57:12.288739Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
#復(fù)制啟動(dòng)腳本
[root@centos8-2 server]# cp /server/mysql/support-files/mysql.server /etc/init.d/mysqld
#配置文件
[root@centos8-2 server]# vim /etc/my.cnf
er=mysql
er=mysql
[mysqld]
user=mysql
basedir=/server/mysql
datadir=/data/mysql/data
server_id=2
port=3306
log_bin = mysql-bin
sync_binlog = 1
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
port = 3306
default-character-set = utf8
[client]
port = 3306
default-character-set = utf8
#啟動(dòng)服務(wù)
[root@centos8-2 server]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/data/centos8-2.err'.
[ OK ]
#登錄數(shù)據(jù)庫(kù)
[root@centos8-2 server]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

?編譯安裝MYSQL5.7?

#安裝相關(guān)依賴包
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison wget openssl-devel.x86_64
#創(chuàng)建用戶和組
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
#下載下載的包導(dǎo)入centos
[root@centos8-2 local]# cd /usr/local/mysql/
[root@centos8-2 mysql]# ls
mysql-5.7.36.tar.gz
[root@centos8-2 mysql]# tar xf mysql-boost-5.7.29.tar.gz
#配置相關(guān)參數(shù)
[root@centos8-2 mysql]# cd mysql-5.7.36
[root@centos8-2 mysql]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
#報(bào)錯(cuò)沒(méi)有安裝boostC++庫(kù)
#解決方法方法
#在cmake命令參數(shù)最后增加-DDOWNLOAD_BOOST=1
#重新運(yùn)行cmake命令報(bào)錯(cuò)
#報(bào)錯(cuò)Could not find rpcgen
#解決方案,訪問(wèn)github搜索rpcsvc
#選擇thkukuk-rpcsvc下載源碼
#導(dǎo)入centos
[root@centos8-2 ~]# tar -xvf rpcsvc-proto-1.4.1.tar
[root@centos8-2 ~]# cd rpcsvc-proto-1.4.1
[root@centos8-2 ~]# ./configure
[root@centos8-2 ~]# make
[root@centos8-2 ~]# make install
#安裝完成后運(yùn)行
[root@centos8-2 ~]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
#編譯安裝(-j指定多核運(yùn)行編譯)
#虛擬機(jī)設(shè)置中調(diào)高CPU加快速度
[root@ctos3 mysql-5.7.29]# make -j 8 && make install
#安裝到82%報(bào)錯(cuò),類似于fatal error:Killed signal terminated program cc1plus
#原因?yàn)閮?nèi)存不足
#解決方法:調(diào)大虛擬機(jī)內(nèi)存,發(fā)現(xiàn)只能調(diào)到3G,實(shí)際16G內(nèi)存,此時(shí)需要關(guān)閉虛擬機(jī)
#在進(jìn)行設(shè)置,設(shè)置為8G后,問(wèn)題解決
#設(shè)置完成后再次運(yùn)行
[root@ctos3 mysql-5.7.29]# make -j 8 && make install
#創(chuàng)建數(shù)據(jù)目錄和修改權(quán)限
mkdir /application/mysql/data #存放數(shù)據(jù)目錄
mkdir /application/mysql/tmp #存放sock目錄
chown -R mysql.mysql /application/mysql/
#配置/etc/my.cnf文件
cat /etc/my.cnf
[mysqld]
port = 3306
socket = /application/mysql/tmp/mysql.sock
user = mysql
basedir = /application/mysql
datadir = /application/mysql/data
pid-file = /application/mysql/data/mysql.pid
sql_mode='ONLY_FULL_GROUP_BY'
log_error = /application/mysql/mysql-error.log
!includedir /etc/my.cnf.d

[client]
port = 3306
socket = /application/mysql/tmp/mysql.sock
#初始化數(shù)據(jù)庫(kù)
/application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/dat
#報(bào)錯(cuò)[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defau
#在my.cnf文件的[mysqld]中增加explicit_defaults_for_timestamp=true
#設(shè)置環(huán)境變量
[root@centos8-2 support-files]# echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile
[root@centos8-2 support-files]# source /etc/profile
[root@centos8-2 support-files]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
#生成啟動(dòng)腳本
[root@centos8-2 ~]# cd /application/mysql/support-files/
[root@centos8-2 support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@centos8-2 support-files]# cp mysql.server /etc/init.d/mysqld
#登錄數(shù)據(jù)庫(kù)
[root@centos8-2 support-files]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.36 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

3、二進(jìn)制安裝mariadb10.4

cd /usr/local
tar xf mariadb-10.5.8-linux-systemd-x86_64.tar.gz
ln -s mariadb-10.5.8-linux-systemd-x86_64 mysql
cd mysql/
useradd -r -s/sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql/
echo 'PATH=/usr/local/mysql/bin/:$PATH' >/etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
./scripts/mysql_install_db --datadir=/data/mysql
#報(bào)錯(cuò)./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install -y libaio
chown -R mysql.mysql /data/mysql
cp support-files/systemd/mariadb.service /usr/lib/systemd/system/
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
mkdir /etc/my.cnf.d
vim /etc/my.cnf.d/mysql-clients.cnf
[mysql]
socket=/data/mysql/mysql.sock
systemctl start mariadb
ln -s /data/mysql/mysql.sock /tmp/
mysql_secure_installation
rm -f /tmp/mysql.sock


本文摘自 :https://blog.51cto.com/u

開通會(huì)員,享受整站包年服務(wù)立即開通 >