mysql8.0.22在centos7.6下的簡單安裝


如果想把mysql安裝得好一些,則嚴重推薦使用壓縮包來安裝,不推薦使用rpm方式。

一般情況下,現在大部分的服務器都是x86-64,少數是arm架構的。

選擇合適的版本,下載即可。

本文中,使用的是 mysql-8.0.22-el7-x86_64.tar.gz (這對centos7的)

為了便於管理,個人推薦的目錄

/soft/mysql/program  --放myql程序文件

/soft/mysql/config     --放mysql的配置文件,配置文件可以隨意命名,例如my.ini,my.cnf,my.config之類都無所謂

當然也可以直接使用默認的/etc/my.cnf 路徑

下面是大概的步驟:

1.解壓文件

2.寫好my.cnf

3.初始化

4.啟動服務,修改root密碼

5.把mysql配置為服務,以便自動啟動

 

步驟1:前置准備

1)包括下載,創建用戶等等基本工作

2)了解需要新的實例要支持什么業務,滿足什么特性

 

步驟2:寫my.cnf,重點幾個:

1)字符集

2)數據目錄

3)端口

4)是否使用root運行(很多時候,我們就用root執行了)

5)密碼驗證方式

6)是否忽略大小寫

7)是否關比bin_log(如果不復制,這個可以節約時間)

8)日志目錄

下面是my.cnf的配置例子:

[client]
port=3318

[mysql]
no-beep
default-character-set=UTF8MB4

[mysqld]
user=root
skip-log-bin
port=3318
#不區分大小寫(linux設置,windows不設置。linux必須初始化的時候設置)
lower_case_table_names=1
# 程序路徑
basedir="/soft/mysql-8.0.22-el7-x86_64"

# 數據庫實例根數據路徑
datadir=/data/mysql

# 創建數據庫和表的默認字符集
character-set-server=UTF8MB4

# 默認存儲引擎
default-storage-engine=INNODB


# General and Slow logging.
log-output=FILE
slow-query-log=0
bulk_insert_buffer_size=32M

# Error 日志
log-error="mysql.err"
 
# 最大並發會話
max_connections=500

# 所有線程可以允許打開的表數量
table_open_cache=1200

# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
# 內存臨時表大小--如果有許多需要臨時表的查詢,而且這些臨時表都挺大的,可以考慮設置大一些
# 當然前提,是您相對比較闊綽,可以有許多內存
tmp_table_size=32M

# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before.  This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=10


# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=0

read_rnd_buffer_size=0

#*** INNODB Specific options ***
# innodb_data_home_dir=0.0

# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
# skip-innodb

# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
#謹慎修改這個參數
innodb_flush_log_at_trx_commit=1

# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=128m

#建議開啟嚴謹模式
innodb_strict_mode=on


#密碼驗證方式
default_authentication_plugin=mysql_native_password

 

步驟3:初始化

如果使用專有的mysql用戶(用戶未必叫這個,不過為了便於識別就叫mysql。如有個人愛好,喜歡叫msql,uglysql可以)啟動配置(這是推薦的,前提是創建了mysql用戶)

bin/mysqld --defaults-file=/opt/mysql/mysql/etc/my.cnf  --initialize  --user=mysql

 

如果想用root且修改配置文件路徑,則可以修改為

bin/mysqld --defaults-file=/data/mysql/config/my.cnf  --initialize  --user=root

 

步驟4:安裝為服務

有時候不一定按照下面就可以安裝為服務,要看系統的情況。

注意:如果修改了路徑則必須修改mysql.server文件

mysql.server一般在support-files下

以下是一般需要修改的片段:

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/soft/mysql-8.0.22-el7-x86_64
datadir=/data/mysql

復制啟動文件  cp mysql.server /etc/init.d/mysqld

賦予可執行權限:# chmod +x /etc/init.d/mysqld

添加為服務:# chkconfig --add mysqld

之后可以使用 systemctl start/stop/status mysqld

也可以直接使用mysql.server start/stop等

 

總結

一個開發環境的安裝還是很容易的,前提是對於性能不需要特別優化的情況。

最后,申明下,以上的配置僅僅能夠滿足一般的開發,要想滿足高性能的配置,遠遠不夠。

作為一個mysql dba,必須掌握:

1)mysql 開發

2)  linux配置

3)  mysql 配置

4)  操作系統、網絡

5)熟悉要優化的系統的業務

6)你的項目,你的團隊的情況

如果認為會建立索引,會寫一些復雜一點點的sql,也認為是優化,那還差太遠太遠了,只能貽笑大方!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM