20230114--Alma Linux 8 二進(jìn)制安裝數(shù)據(jù)庫(MySQL8)

依賴包安裝

# dnf -y install wget  cmake gcc gcc-c++ ncurses  ncurses-devel  libaio-devel  openssl openssl-devel perl

創(chuàng)建mysql用戶

# groupadd mysql
# useradd mysql -d /var/lib/mysql/ -g mysql
# tail -1  /etc/passwd
mysql:x:1000:1000::/var/lib/mysql/:/bin/bash

獲取mysql-8.0.31安裝包

# wget -c https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
# tar -xf mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
# mv  mysql-8.0.31-linux-glibc2.12-x86_64 /usr/local/
# ln -s /usr/local/mysql-8.0.31-linux-glibc2.12-x86_64 /usr/local/mysql

數(shù)據(jù)庫目錄創(chuàng)建

# mkdir /usr/local/mysql/tmp
# mkdir -p /var/lib/mysql/{mysql_data,mysql_log,mysql_tmp}
# mkdir -p /var/lib/mysql/mysql_log/{binlog,undolog}
# mkdir -p /var/lib/mysql/backup

ENV設(shè)置

# cat <<- 'EOF' | tee -a /etc/profile.d/mysql.sh
### MYSQL ENV ###
MYSQL_HOME=/usr/local/mysql
PATH=$PATH:${MYSQL_HOME}/bin
export PATH
EOF
# source  /etc/profile.d/mysql.sh

my.cnf配置

# cat <<- 'EOF' | tee -a /usr/local/mysql/my.cnf
[client]
port                            = 5550
socket                          = /usr/local/mysql/tmp/mysql.sock
default_character_set           = utf8mb4

[mysqldump]
quick
max_allowed_packet              = 67108864

[mysql]
no_auto_rehash
default_character_set           = utf8mb4

[mysqld_safe]
log_error                       = /var/lib/mysql/mysql_log/error.log

[mysqld]
server_id                       = 12     # custom
port                            = 5550
socket                          = /usr/local/mysql/tmp/mysql.sock
pid_file                        = /usr/local/mysql/tmp/mysql.pid
basedir                         = /usr/local/mysql
datadir                         = /var/lib/mysql/mysql_data
tmpdir                          = /var/lib/mysql/mysql_tmp
replica_load_tmpdir             = /var/lib/mysql/mysql_tmp
lower_case_table_names          = 1
skip_name_resolve               = ON    # custom
skip_external_locking           = ON
event_scheduler                 = ON
secure_file_priv                = /var/lib/mysql/backup     # custom
explicit_defaults_for_timestamp = 1
open_files_limit                = 65535

mysqlx_port                     = 55550
mysqlx_socket                   = /usr/local/mysql/tmp/mysqlx.sock

### ------------------------------------------
### connection & session
### ------------------------------------------
# bind_address                  = ''
max_connections                 = 1000     # custom
max_user_connections            = 800      # custom
max_connect_errors              = 99999999
connect_timeout                 = 30
wait_timeout                    = 3600
interactive_timeout             = 3600
init_connect                    = 'SET NAMES utf8mb4'
character_set_server            = utf8mb4
collation_server                = utf8mb4_0900_ai_ci
replica_net_timeout             = 900
net_read_timeout                = 30
net_write_timeout               = 60
net_buffer_length               = 8192
max_execution_time              = 3600000    # custom: (ms)
thread_cache_size               = 768

# mysqlx_bind_address             = ''
mysqlx_max_connections          = 800       # custom

### ------------------------------------------
### log
### ------------------------------------------
log_timestamps                  = system
log_error_verbosity             = 2
log_error                       = /var/lib/mysql/mysql_log/error.log
log_bin                         = /var/lib/mysql/mysql_log/binlog/binlog
log_bin_index                   = /var/lib/mysql/mysql_log/binlog/binlog.index
max_binlog_size                 = 134217728
binlog_expire_logs_seconds      = 604800    # custom: default(7days) /s
binlog_cache_size               = 4194304
binlog_format                   = ROW
binlog_row_image                = minimal
sync_binlog                     = 1
slow_query_log                  = ON        # custom
long_query_time                 = 1         # custom
# log_queries_not_using_indexes = ON
# log_throttle_queries_not_using_indexes   = 60
slow_query_log_file             = /var/lib/mysql/mysql_log/slow.log
relay_log                       = /var/lib/mysql/mysql_log/relaylog
relay_log_index                 = /var/lib/mysql/mysql_log/relaylog.index
max_relay_log_size              = 536870912
innodb_undo_directory           = /var/lib/mysql/mysql_log/undolog
#innodb_undo_tablespaces_total   = 4
#innodb_undo_tablespaces_implicit = 2        # innodb-created
#innodb_undo_tablespaces_explicit = 2        # user-created
#innodb_undo_tablespaces_active  = 4

### ------------------------------------------
### innodb
### ------------------------------------------
innodb_file_per_table           = 1
innodb_open_files               = 60000
innodb_buffer_pool_size         = 6012954214       # custom(mem * 70%)
innodb_log_file_size            = 536870912   # custom(innodb_buffer_pool_size * 25%)
innodb_data_file_path           = ibdata1:1024M:autoextend       # custom
innodb_flush_method             = O_DIRECT
innodb_log_buffer_size          = 8388608
innodb_log_files_in_group       = 2
innodb_flush_log_at_trx_commit  = 1
innodb_write_io_threads         = 4    # custom: cpu core
innodb_read_io_threads          = 4    # custom: cpu core
innodb_thread_concurrency       = 0
innodb_purge_rseg_truncate_frequency = 128
innodb_page_size                = 16384
innodb_max_dirty_pages_pct      = 60
innodb_lock_wait_timeout        = 100
innodb_autoinc_lock_mode        = 2    # only for [binlog_format]=row

### ------------------------------------------
### table & query
### ------------------------------------------
transaction_isolation           = REPEATABLE-READ        # READ-COMMITTED
key_buffer_size                 = 67108864
max_allowed_packet              = 67108864
table_open_cache                = 512
sort_buffer_size                = 2097152    # custom: memeory < 16GB, suggest to set 2M
read_rnd_buffer_size            = 2097152    # custom: memeory < 16GB, suggest to set 2M
read_buffer_size                = 2097152    # custom: memeory < 16GB, suggest to set 2M
join_buffer_size                = 2097152    # custom: memeory < 16GB, suggest to set 2M
tmp_table_size                  = 67108864
max_heap_table_size             = 8388608
bulk_insert_buffer_size         = 16777216
group_concat_max_len            = 1048576

### ------------------------------------------
### replication
### ------------------------------------------
log_replica_updates             = 1
skip_replica_start              = ON
gtid_mode                       = ON
enforce_gtid_consistency        = ON
sync_source_info                = 10000
relay_log_purge                 = 1
# replicate_wild_ignore_table     = configdb.%    # custom: only for slave
# replicate_wild_ignore_table     = mysql.%    # custom: only for slave
# relay_log_recovery              = ON    # custom: only for slave
# read_only                       = ON    # custom: only for slave
EOF

修改目錄權(quán)限

# chown -R mysql:mysql /usr/local/mysql-8.0.31-linux-glibc2.12-x86_64/
# chown -R mysql:mysql /usr/local/mysql
# chown -R mysql:mysql /var/lib/mysql/

數(shù)據(jù)庫初始化

# mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql/mysql_data

創(chuàng)建啟動文件

# cat <<- 'EOF' | tee -a /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Service]
Type=forking
User=mysql
Group=mysql
PIDFile=/usr/local/mysql/tmp/mysql.pid
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --daemonize
ExecStartPost=/usr/bin/sleep 1
Restart=on-failure
ExecStop=/usr/bin/kill -s QUIT $MAINPID

TimeoutSec=0
LimitNOFILE=65535
RestartPreventExitStatus=1
PermissionsStartOnly=true
PrivateTmp=false

[Install]
WantedBy=multi-user.target
EOF

啟動mysql

# systemctl daemon-reload
# systemctl start mysqld
# systemctl enable mysqld
# systemctl status mysqld

查看數(shù)據(jù)庫初始化密碼

# cat /var/lib/mysql/mysql_log/error.log  | grep localhost
2023-01-13T22:10:15.295310+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: VR/yjfEhS24T

確認(rèn)數(shù)據(jù)庫版本

# mysqladmin --version
mysqladmin  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)

修改mysql數(shù)據(jù)庫root密碼

# ln -s /usr/local/mysql/tmp/mysql.sock /tmp/mysql.sock
# 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.31

Copyright (c) 2000, 2022, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> 

開啟開啟mysql的遠(yuǎn)程訪問

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> 

錯誤解決

1)mysql登錄報錯mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
登錄報錯
# mysql -uroot -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

解決辦法:
# ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
2)mysql登錄報錯ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
登錄報錯
# mysql -hlocalhost -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解決辦法:
# ln -s /usr/local/mysql/tmp/mysql.sock /tmp/mysql.sock

參考URL

http://www.mysqlcalculator.com/
https://dev.mysql.com/doc/refman/5.7/en/server-option-variable-reference.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市搬男,隨后出現(xiàn)的幾起案子叙量,更是在濱河造成了極大的恐慌滓鸠,老刑警劉巖奢啥,帶你破解...
    沈念sama閱讀 211,265評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件诀黍,死亡現(xiàn)場離奇詭異,居然都是意外死亡咙崎,警方通過查閱死者的電腦和手機(jī)优幸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,078評論 2 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來褪猛,“玉大人网杆,你說我怎么就攤上這事∥找” “怎么了跛璧?”我有些...
    開封第一講書人閱讀 156,852評論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長新啼。 經(jīng)常有香客問我追城,道長,這世上最難降的妖魔是什么燥撞? 我笑而不...
    開封第一講書人閱讀 56,408評論 1 283
  • 正文 為了忘掉前任座柱,我火速辦了婚禮,結(jié)果婚禮上物舒,老公的妹妹穿的比我還像新娘色洞。我一直安慰自己,他們只是感情好冠胯,可當(dāng)我...
    茶點故事閱讀 65,445評論 5 384
  • 文/花漫 我一把揭開白布火诸。 她就那樣靜靜地躺著,像睡著了一般荠察。 火紅的嫁衣襯著肌膚如雪置蜀。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,772評論 1 290
  • 那天悉盆,我揣著相機(jī)與錄音盯荤,去河邊找鬼。 笑死焕盟,一個胖子當(dāng)著我的面吹牛秋秤,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播脚翘,決...
    沈念sama閱讀 38,921評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼灼卢,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了堰怨?” 一聲冷哼從身側(cè)響起芥玉,我...
    開封第一講書人閱讀 37,688評論 0 266
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎备图,沒想到半個月后灿巧,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赶袄,經(jīng)...
    沈念sama閱讀 44,130評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,467評論 2 325
  • 正文 我和宋清朗相戀三年抠藕,在試婚紗的時候發(fā)現(xiàn)自己被綠了饿肺。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,617評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡盾似,死狀恐怖敬辣,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情零院,我是刑警寧澤溉跃,帶...
    沈念sama閱讀 34,276評論 4 329
  • 正文 年R本政府宣布,位于F島的核電站告抄,受9級特大地震影響撰茎,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜打洼,卻給世界環(huán)境...
    茶點故事閱讀 39,882評論 3 312
  • 文/蒙蒙 一龄糊、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧募疮,春花似錦炫惩、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,740評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至芭毙,卻和暖如春爸舒,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背稿蹲。 一陣腳步聲響...
    開封第一講書人閱讀 31,967評論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留鹊奖,地道東北人苛聘。 一個月前我還...
    沈念sama閱讀 46,315評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像忠聚,于是被迫代替她去往敵國和親设哗。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,486評論 2 348

推薦閱讀更多精彩內(nèi)容