centos docker 安裝mysql 8.0


centos 版本  CentOS Linux release 7.5.1804 (Core)

內核版本: 3.10.0-862.el7.x86_64

下載最新版mysql

docker pull mysql

啟動鏡像

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=woshimima -d mysql

進入命令

docker exec -it mysql /bin/bash

連接數據庫

mysql -uroot -p woshimima

查看編碼格式

show variables like "%char%";

utf8mb4 代表可以添加emoji ,所以要修改格式

set character_set_client = utf8mb4;
set character_set_connection = utf8mb4;
set character_set_database = utf8mb4;
set character_set_filesystem = utf8mb4;
set character_set_results = utf8mb4;
set character_set_server = utf8mb4;
FLUSH PRIVILEGES;

這個只是暫時修改了編碼格式,重啟了mysql還是變回了原來的樣子。氣不氣?要去文件里修改配置,

#/etc/mysql/conf.d/mysql.cnf 這個就是文件位置,替換一下 docker cp D:\nginx-1.13.12\conf.d\mysql.cnf 193290698eb9:/etc/mysql/conf.d/mysql.cnf
[client] #設置客戶端編碼 default
-character-set=utf8mb4

這樣就修改完成了,重啟進入查看一下

完美

 

 

 

退出。重新進入 連接數據庫 修改root密碼

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'woshimima';
FLUSH PRIVILEGES;

創建表

create database weiqinke;

創建用戶

CREATE USER weiqinke IDENTIFIED BY 'woshimima';

給weiqinke 這個表加一個用戶並刷新權限

grant all privileges on weiqinke.* to 'weiqinke'@'%' with grant option;
flush privileges;

刪除Root的遠程權限

delete from user where user='root'and host='%';

此時結束了。

下面是配置,此項配置占用了382M內存,原始配置占用了462M,下降了大約80M內存,本身就是2G,暫時還能用,后期看到好的參數,再進行調優吧

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
innodb_buffer_pool_size=1000000000
# 按事物刷盤,刷日志
innodb_flush_log_at_trx_commit=1

# 臟頁占innodb_buffer_pool_size的比例時,觸發刷臟頁到磁盤
# 25%~50%
innodb_max_dirty_pages_pct=30

# 后台進程最大IO性能指標
# 默認200,如果SSD,調整為5000~20000
innodb_io_capacity=100

# 全量日志建議關閉
# 默認關閉
general_log=0

table_open_cache=2000
tmp_table_size=12M
thread_cache_size=10
myisam_max_sort_file_size=1G
myisam_sort_buffer_size=15M
key_buffer_size=8M
read_buffer_size = 30K
read_rnd_buffer_size=256K
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M
innodb_buffer_pool_size=32M
innodb_log_file_size=48M
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=256K
max_allowed_packet=4M
max_connect_errors=100
open_files_limit=4161
sort_buffer_size=256K
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Custom config should go here
!includedir /etc/mysql/conf.d/

 下面這3行,占用只有285M左右,下降了大約177M

performance_schema_max_table_instances=600
table_definition_cache=400
table_open_cache=256

 


免責聲明!

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



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