【mysql安裝和卸載之二進制包】

1.環境準備

查看當前Linux操作系統版本爲CentOS release 6.10

[root@ufo130 ~]# lsb_release -a
LSB Version:	:base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:	CentOS
Description:	CentOS release 6.10 (Final)
Release:	    6.10
Codename:	    Final

2.下載安裝包

下載網址
https://dev.mysql.com/downloads/mysql/
下載對應操作系統的mysql安裝包(沒有賬號可以免費註冊一個賬號)
在這裏插入圖片描述

3.執行安裝

可參考第4步先卸載乾淨,再安裝(如果之前有安裝,或安裝在不同目錄下不用卸載)
用root登錄操作系統,增加mysql用戶和組,數據庫將安裝在此用戶下(如若已存在MySQL用戶,在確定不影響其他功能的情況下,可將之刪除,並重建)

[root@ufo130 ~]# userdel -r mysql
[root@ufo130 ~]# groupadd mysql
[root@ufo130 ~]# useradd -g mysql mysql

創建安裝目錄,上傳安裝包等操作

[root@ufo130 ~]# mkdir -p /opt/mysql
[root@ufo130 ~]# cd /opt/mysql
[root@ufo130 mysql]# ll
total 473712
-rw-r--r-- 1 root root 485074552 Apr 15 01:22 mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
[root@ufo130 mysql]# tar xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz 
[root@ufo130 mysql]# ln -s mysql-8.0.19-linux-glibc2.12-x86_64 mysql
[root@ufo130 mysql]# cd mysql
[root@ufo130 mysql]# mkdir mysql-files
[root@ufo130 mysql]# chown mysql:mysql mysql-files
[root@ufo130 mysql]# chmod 750 mysql-files

在數據目錄下創建系統數據庫和系統表,user表示這些數據庫和表的owner是此用戶(注意輸出日誌含有root用戶臨時密碼:Lb_aW0Oi&gYe)

[root@ufo130 mysql]# bin/mysqld --initialize --user=mysql
2020-04-15T03:43:03.992059Z 0 [System] [MY-013169] [Server] /opt/mysql/mysql-8.0.19-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 8718
2020-04-15T03:43:17.343810Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Lb_aW0Oi&gYe
[root@ufo130 mysql]# bin/mysql_ssl_rsa_setup --datadir=/opt/mysql/mysql/data

配置環境變量,配置啓動服務

[root@ufo130 ~]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@ufo130 ~]# source /etc/profile
[root@ufo130 mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
[root@ufo130 mysql]# vim /etc/init.d/mysql.server 
basedir=/opt/mysql/mysql/
datadir=/opt/mysql/mysql/data

啓動服務、修改臨時密碼、重啓生效(修改的密碼必須滿足密碼策略:字母大小寫、數字和特殊字符,長度不小於8)

[root@ufo130 mysql]# service mysql.server start
Starting MySQL SUCCESS!
[root@ufo130 mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

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 'Ufo_123456';
Query OK, 0 rows affected (0.14 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
[root@ufo130 ~]# service mysql.server restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.... SUCCESS! 

4.執行卸載

1.關閉數據庫 service mysql.server stop
2.刪除mysql用戶(可選、不影響其他使用)userdel -r mysql
2.刪除之前的環境變量配置 /etc/profile
3.刪除之前的啓動服務 /etc/init.d/mysql.server
4.刪除整個安裝目錄 /opt/mysql
7.刪除全局參數文件(如果有my.cnf)
注意:具體的目錄、配置等取決於之前配置過的位置

5.文件佈局

[root@ufo130 mysql]# ll
total 440
drwxr-xr-x  2  7161 31415   4096 Dec 10 07:32 bin
drwxr-x---  6 mysql mysql   4096 Apr 15 12:43 data
drwxr-xr-x  2  7161 31415   4096 Dec 10 07:32 docs
drwxr-xr-x  3  7161 31415   4096 Dec 10 07:32 include
drwxr-xr-x  6  7161 31415   4096 Dec 10 07:32 lib
-rw-r--r--  1  7161 31415 405571 Dec 10 03:53 LICENSE
drwxr-xr-x  4  7161 31415   4096 Dec 10 07:32 man
drwxr-x---  2 mysql mysql   4096 Apr 15 11:40 mysql-files
-rw-r--r--  1  7161 31415    687 Dec 10 03:53 README
drwxr-xr-x 28  7161 31415   4096 Dec 10 07:32 share
drwxr-xr-x  2  7161 31415   4096 Dec 10 07:32 support-files

常見文件佈局
在這裏插入圖片描述

6.總結

優點:安裝簡單,可以安裝到任何路徑下,靈活性好。一臺服務器可以安裝多個mysql。
缺點:已經編譯過,性能不如源碼編譯的好,不能靈活的定製編譯參數。

參考官方:https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章