centos docker 安装mysql 8.0

时间:2023-03-09 18:23:04
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 : -e MYSQL_ROOT_PASSWORD=woshimima -d mysql

进入命令

docker exec -it mysql /bin/bash

连接数据库

mysql -uroot -p woshimima

查看编码格式

show variables like "%char%";

centos docker 安装mysql 8.0

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

这样就修改完成了,重启进入查看一下

centos docker 安装mysql 8.0

完美

退出。重新进入 连接数据库 修改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=
# 按事物刷盘,刷日志
innodb_flush_log_at_trx_commit= # 脏页占innodb_buffer_pool_size的比例时,触发刷脏页到磁盘
# %~%
innodb_max_dirty_pages_pct= # 后台进程最大IO性能指标
# 默认200,如果SSD,调整为5000~
innodb_io_capacity= # 全量日志建议关闭
# 默认关闭
general_log= table_open_cache=
tmp_table_size=12M
thread_cache_size=
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=
innodb_log_buffer_size=1M
innodb_buffer_pool_size=32M
innodb_log_file_size=48M
innodb_autoextend_increment=
innodb_buffer_pool_instances=
innodb_concurrency_tickets=
innodb_old_blocks_time=
innodb_open_files=
innodb_file_per_table=
innodb_checksum_algorithm=
back_log=
flush_time=
join_buffer_size=256K
max_allowed_packet=4M
max_connect_errors=
open_files_limit=
sort_buffer_size=256K
table_definition_cache=
binlog_row_event_max_size=8K
sync_master_info=
sync_relay_log=
sync_relay_log_info= # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links= # Custom config should go here
!includedir /etc/mysql/conf.d/

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

performance_schema_max_table_instances=
table_definition_cache=
table_open_cache=