第10周作業
通過編譯、二進制安裝MySQL
1、源碼包下載,官網下載地址:https://downloads.mysql.com/archives/community/
點擊下載,還有boost_1_59_0.tar.gz這個源碼包也要提前下載好,然后將源碼包上傳到Linux系統
[root@centos7 ~]#ll
total 131916
-rw-r--r-- 1 root root 51363998 Aug 9 14:19 mysql-boost-5.7.30.tar.gz
-rw-r--r-- 1 root root 83709983 Aug 9 14:25 boost_1_59_0.tar.gz
2、安裝相關依賴包
[root@centos7 ~]#yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper
3、創建用戶和數據目錄
[root@centos7 ~]#useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@centos7 ~]#id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)
4、創建數據庫目錄,修改權限
[root@centos7 ~]#mkdir /data/mysql -pv
mkdir: created directory ‘/data/mysql’
[root@centos7 ~]#chown mysql.mysql /data/mysql/
[root@centos7 ~]#ll -d /data/mysql/
drwxr-xr-x 2 mysql mysql 6 Jan 27 20:42 /data/mysql/
5、解壓縮源碼包
[root@centos7 ~]#tar xvf mysql-boost-5.7.30.tar.gz -C /usr/local/src
[root@centos7 ~]#tar xvf boost_1_59_0.tar.gz -C /usr/local/src
6、源碼編譯安裝 MySQL
[root@centos7 ~]#cd /usr/local/src/mysql-5.7.30/
[root@centos7 mysql-5.7.30]#pwd
/usr/local/src/mysql-5.7.30
[root@centos7 mysql-5.7.30]#cmake . \
> -DCMAKE_INSTALL_PREFIX=/apps/mysql \
> -DMYSQL_DATADIR=/data/mysql/ \
> -DSYSCONFDIR=/etc/ \
> -DMYSQL_USER=mysql \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
> -DWITH_DEBUG=0 \
> -DWITH_READLINE=1 \
> -DWITH_SSL=system \
> -DWITH_ZLIB=system \
> -DWITH_LIBWRAP=0 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DDOWNLOAD_BOOST=1 \
> -DWITH_BOOST=/usr/local/src/boost_1_59_0
[root@centos7 mysql-5.7.30]#make && make install
7、準備環境變量
[root@centos7 mysql-5.7.30]#echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos7 mysql-5.7.30]#. /etc/profile.d/mysql.sh
8、修改配置文件
[root@centos7 mysql-5.7.30]#cd /apps/mysql/
[root@centos7 mysql]#pwd
/apps/mysql
[root@centos7 mysql]#vim /etc/my.cnf
[mysqld]
explicit_defaults_for_timestamp=true
datadir=/data/mysql/
basedir=/apps/mysql/bin/mysql/
port=3306
pid-file=/data/mysql/mysql.pid
socket=/data/mysql/mysql.socket
symbolic-links=0
character_set_server=utf8
user=mysql
[mysqld_safe]
log-error=/data/mysql/mysql.log
[client]
port=3306
socket=/data/mysql/mysql.socket
default-character-set=utf8
9、初始化數據庫
[root@centos7 mysql]#bin/mysqld --initialize-insecure --datadir=/data/mysql/ --user=mysql
10、準備啟動腳本,并啟動服務
[root@centos7 mysql]#cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos7 mysql]#chkconfig --add mysqld
[root@centos7 mysql]#systemctl start mysqld
[root@centos7 mysql]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 80 [::]:3306 [::]:*
11、修改密碼,設置的密碼一定要記好(大寫字母、小寫字母、數字加標點符號,密碼要定期更換)
[root@centos7 mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 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> status
--------------
mysql Ver 14.14 Distrib 5.7.30, for Linux (x86_64) using EditLine wrapper
Connection id: 2
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.30 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /data/mysql/mysql.socket
Uptime: 15 min 17 sec
Threads: 1 Questions: 5 Slow queries: 0 Opens: 105 Flush tables: 1 Open tables: 98 Queries per second avg: 0.005
--------------
mysql> alter user root@'localhost' identified by 'MySQL@2022.';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
二進制安裝
1、安裝相關包
yum -y install libaio numactl-libs
2、創建用戶和組
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
3、準備程序文件
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-linuxglibc2.12-x86_64.tar.gz
tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local/
ln -s mysql-5.7.31-linux-glibc2.12-x86_64/ mysql
chown -R root.root /usr/local/mysql/
4、準備環境變量
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
5、準備配置文件
cp /etc/my.cnf{,.bak}
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
6、初始化數據庫文件并提取root密碼,生成 root 空密碼
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
7、準備服務腳本和啟動
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
8、修改口令
mysqladmin -uroot password 123456
9、測試登錄
mysql -uroot -p123456
浙公網安備 33010602011771號