Mysql簡介以及安裝-轉自老男孩old郭

1、官方定義的MySQL DBA工作內容

(1)運維DBA
初級:各版本、各平臺安裝搭建、升級
中級:體系結構原理、基礎管理(啓動關閉、初始化配置文件管理、多實例管理、用戶權限管理、基本SQL(增刪改查))、
     日誌管理、備份與恢復、主從複製(構建、狀態監控) 
高級:高可用(MGR、InnoDB Cluster)、高性能(優化)
(2)開發DBA
懂至少一門開發語言 :JAVA、Python
基本SQL語句深入學習(增刪改查)、數據庫結構設計(建模)
高級SQL:存儲過程、函數、觸發器、視圖、事件

2、老男孩MySQL課程-2019-03月-中級DBA要求(80%以上)

(1)MySQL 5.7 安裝部署(二進制)*****
    編譯自己擴展
(2)MySQL升級步驟擴展 ***
(3)MySQL5.7 體系結構原理 *****
(4)MySQL基礎管理  *****
(5)基礎SQL語句使用 *****
(6)SQL高級應用  ***
(7)Information_schema獲取元數據 ***
(8)索引、執行計劃管理(基礎優化)*****
(9)存儲引擎  *****
(10)日誌管理 *****
(11)備份與恢復 ******
(12)主從複製及架構演變 ******
(13)傳統的高可用及讀寫分離(MHA&Atlas)****
(14)傳統分佈式架構設計與實現-擴展(Mycat--->DBLE,DRDS)**
(15)MySQL 5.7 高可用及分佈式架構-擴展(MGR,InnoDB Cluster)***
(16)MySQL優化(安全、性能) ****
(17)MySQL 監控(zabbix、Open-falcon)    ****
 (18) RDS(阿里雲課程)    *****

額外要會的:
    Redis
    mongodb     
瞭解: 
    PG
    Oracle  

3、DBA職業素養


3.1、人品

責任-----權利

3.2

3.2.1、嚴謹

磁帶庫----->備份軟件-----17樓
數據庫修改\刪除類的命令時 再三考慮,而且要有理論或者實踐的支撐

3.2.2 請收起你的好奇心!!!!!

注意規範:
脫庫? 華住網(ip root 密碼),“脫敏”!!!!!。
學會保護自己!!!

3.3、細心

把最簡單的事情做的最漂亮,最專業。
不要怕成功的門很擁擠,因爲很多人在半路就已經放棄了.
                                           ----oldguo                     

3.4、心態

別惹事,出事別怕事

3.5、熟悉操作系統(精通)

3.6、熟悉公司業務

業務?
    產品的功能
    用戶的行爲(熱功能,熱數據)      

3.7、熟悉行業

熟悉行業發展趨勢
版本
數據庫產品類型
https://db-engines.com/en/ranking

3.8、喜歡數據庫

體驗很重要

第二章: MySQL 介紹和安裝

1、什麼是數據?

數據:文字、圖片、視頻。。。人類認知的數據表現方式
計算機:二進制、16進制的機器語言
基於數據的重要性和複雜性的不同,我們可能有不同的管理方式。

哪些數據是適合存儲到數據庫的呢?
重要性比較高的
關係較複雜的數據

2、什麼是數據庫管理系統(DBMS)?

RDBMS: 關係型數據庫管理系統
比較適合於,安全級別要求高的數據以及關係較複雜的數據

NoSQL:非關係型數據庫管理系統
適合於高性能存取數據,一般是配合RDBMS進行使用的
針對大數據處理分析,分佈式架構更加擅長

3、數據庫管理系統種類

RDBMS  :
MySQL 、Oracle、MSSQL(SQL Server)、PG
 
NoSQL:Not Only SQL
鍵-值(key-value):Redis, memcached
文檔(document):Mongodb

4、MySQL簡介及產品線

4.1 MySQL行業主流版本:

    5.6  
    5.7    
    8.0(現在開始研究新特性)

4.2 企業版本選擇(MySQL分支版本),筆試題

Oracle:
      MySQL官方版
紅帽  :
      MariaDB
Percona:
      PerconaDB

4.3 版本選擇建議要上新環境

1.一般選擇官方主流版本:5.6,5.7 
2.GA(穩定發佈版)
3.6-12月的產品版本

4.4 課程版本:

5.7.20  二進制安裝,其他安裝方式自己擴展

4.5 如何獲取MySQL軟件

企業版:Enterprise  , 互聯網行業一般不選擇.
社區版本:選擇
源碼包:source code    .tar.gz   
通用二進制   
面試題:
你們公司用什麼版本數據庫? 具體什麼小版本號?
5.6.20 5.6.34 5.6.36  5.6.38  5.6.40    
5.7.18  5.7.20  5.7.22

5、MySQL二進制安裝

5.1.創建軟件目錄:

[root@db01 ~]# mkdir -p /app/
上傳軟件到此目錄

5.2. 解壓並改名爲mysql

[root@db01 app]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
[root@db01 app]# ls -l /app/mysql/
total 36
drwxr-xr-x  2 root root   4096 Mar  4 14:55 bin
-rw-r--r--  1 7161 31415 17987 Sep 13  2017 COPYING
drwxr-xr-x  2 root root     55 Mar  4 14:55 docs
drwxr-xr-x  3 root root   4096 Mar  4 14:55 include
drwxr-xr-x  5 root root    229 Mar  4 14:55 lib
drwxr-xr-x  4 root root     30 Mar  4 14:55 man
-rw-r--r--  1 7161 31415  2478 Sep 13  2017 README
drwxr-xr-x 28 root root   4096 Mar  4 14:55 share
drwxr-xr-x  2 root root     90 Mar  4 14:55 support-files

修改環境變量:

vim /etc/profile
export PATH=/app/mysql/bin:$PATH
[root@db01 bin]# source /etc/profile

5.3. 建立mysql用戶和組(如果已有可忽略)

 useradd mysql 

5.4. 創建相關目錄並修改權限

 mkdir /data/mysql -p 
 chown -R mysql.mysql /app/*
 chown -R mysql.mysql /data/*

5.5 初始化數據(建庫)

方法一:

初始化數據,初始化管理員的臨時密碼
mysqld --initialize  --user=mysql --basedir=/app/mysql --datadir=/data/mysql

2019-04-18T03:21:53.381108Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-18T03:21:54.583415Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-18T03:21:54.697859Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-18T03:21:54.760821Z 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: 1daa0c57-6189-11e9-bc80-000c294234c8.
2019-04-18T03:21:54.770856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-18T03:21:54.772016Z 1 [Note] A temporary password is generated for root@localhost: 9LN.fh_Ea#uU

image.png

 

報錯原因: Linux系統中缺少libaio-devel 軟件包
解決:
yum install -y libaio-devel

image.png

報錯原因:
在/data/mysql 存在文件
解決:
\rm -rf /data/mysql/*

新特性重要說明:

5.7開始,MySQL加入了全新的 密碼的安全機制:
1.初始化完成後,會生成臨時密碼(顯示到屏幕上,並且會往日誌中記一份)
2.密碼複雜度:長度:超過12位? 複雜度:字符混亂組合
3.密碼過期時間180天

 

方法二 :
初始化數據,初始化管理員的密碼爲空

\rm -rf  /data/mysql/*
[root@db01 ~]# mysqld --initialize-insecure  --user=mysql --basedir=/app/mysql --datadir=/data/mysql

2019-04-18T03:37:43.146018Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-18T03:37:43.892132Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-18T03:37:43.970412Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-18T03:37:44.029490Z 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: 5378f3b3-618b-11e9-9164-000c294234c8.
2019-04-18T03:37:44.041469Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-18T03:37:44.042348Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@db01 ~]# 

[root@db01 ~]# cd /data/mysql/
[root@db01 mysql]# ll
total 110628
-rw-r----- 1 mysql mysql       56 Apr 18 11:37 auto.cnf
-rw-r----- 1 mysql mysql      419 Apr 18 11:37 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Apr 18 11:37 ibdata1
-rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Apr 18 11:37 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 Apr 18 11:37 mysql
drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 performance_schema
drwxr-x--- 2 mysql mysql     8192 Apr 18 11:37 sys
[root@db01 mysql]# 

註釋:5.6初始化的區別

 

/application/mysql/scripts/mysql_install_db  --user=mysql --datadir=/application/mysql/data --basedir=/application/mysql

5.6 書寫默認配置文件

vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>

5.7 配置啓動腳本:

[root@db01 mysql]# cd /app/mysql/support-files
[root@db01 support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/mysql/db01.err'.
 SUCCESS! 
cp mysql.server    /etc/init.d/mysqld

5.8 使用systemd管理mysql

vim /etc/systemd/system/mysqld.service 
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://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=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

注意:將原來模式啓動mysqld先關閉,然後再用systemd管理。

systemctl  start/stop/restart/status   mysqld

6. 安裝後的簡單管理

[root@db01 ~]# mysqladmin -uroot -p password 123
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

5.6版本:
select user,password,host from mysql.user;
5.7 中用戶基本信息
select user,authentication_string,host from mysql.user;
desc  mysql.user;

小結:
1.版本 (主流版本的GA時間瞭解一下)

5.6 5.7 
5.6.38   5.7.20 
20170913 
(1) 初始化方式變了
mysql_install_db   
mysqld  --initialize-insecure
(2) 用戶安全
12位
180
4種複雜度

(3)密碼字段
authentication_strings

2.安裝方法:

二進制
源碼
yum 

3.建庫(初始化數據庫)

mysqld --intialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql 

4.簡易的配製文件/etc/my.cnf

user 
basedir
datadir 
server_id
port
socket 
  1. 管理員密碼
mysqladmin -uroot -p password xx



作者:wwwoldguocom
鏈接:https://www.jianshu.com/p/dd7137c4efa5
 

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