返回列表 发帖

CentOS8_Yum安装MySQL8.0

查看操作系统的信息:
[root@redhat8 ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
[root@redhat8 ~]#
[root@redhat8 ~]# uname -r
4.18.0-193.el8.x86_64

[root@redhat8 ~]# hostname
redhat8.zhuohua.store
[root@redhat8 ~]# cat /etc/hostname
redhat8.zhuohua.store

[root@redhat8 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:15:ba:0c brd ff:ff:ff:ff:ff:ff
    inet 192.168.168.155/24 brd 192.168.168.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::92ab:5fb4:5373:ad53/64 scope link dadfailed tentative noprefixroute
       valid_lft forever preferred_lft forever
    inet6 fe80::f6ea:de6f:f7bb:129b/64 scope link noprefixroute
       valid_lft forever preferred_lft forever


关闭SELinux:(默认是开启的,要关闭)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config


删除原有的MySQL::
[root@centos8 ~]# dnf -y remove @mysql
[root@centos8 ~]# dnf module reset mysql
[root@centos8 ~]# dnf -y module disable mysql



给MySQL8.0创建一个仓库文件:
[root@redhat8 ~]# cat /etc/yum.repos.d/mysql-community.repo
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/8/$basearch/
enabled=1
gpgcheck=0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/8/$basearch/
enabled=1
gpgcheck=0

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/8/$basearch/
enabled=1
gpgcheck=0



先查看新Yum源里MySQL8.0的具体版本:
[root@redhat8 ~]# yum list |grep mysql-community
mysql-community-client.x86_64                          8.0.26-1.el8                                      mysql80-community         
mysql-community-client-debuginfo.x86_64                8.0.26-1.el8                                      mysql80-community         
mysql-community-client-plugins.x86_64                  8.0.26-1.el8                                      mysql80-community         
mysql-community-client-plugins-debuginfo.x86_64        8.0.26-1.el8                                      mysql80-community         
mysql-community-common.x86_64                          8.0.26-1.el8                                      mysql80-community         
mysql-community-debuginfo.x86_64                       8.0.26-1.el8                                      mysql80-community         
mysql-community-debugsource.x86_64                     8.0.26-1.el8                                      mysql80-community         
mysql-community-devel.x86_64                           8.0.26-1.el8                                      mysql80-community         
mysql-community-libs.x86_64                            8.0.26-1.el8                                      mysql80-community         
mysql-community-libs-debuginfo.x86_64                  8.0.26-1.el8                                      mysql80-community         
mysql-community-server.x86_64                          8.0.26-1.el8                                      mysql80-community         
mysql-community-server-debug.x86_64                    8.0.26-1.el8                                      mysql80-community         
mysql-community-server-debug-debuginfo.x86_64          8.0.26-1.el8                                      mysql80-community         
mysql-community-server-debuginfo.x86_64                8.0.26-1.el8                                      mysql80-community         
mysql-community-test.x86_64                            8.0.26-1.el8                                      mysql80-community         
mysql-community-test-debuginfo.x86_64                  8.0.26-1.el8                                      mysql80-community



连接公网单纯下载MySQL8.0的相关RPM软件包:(存放软件包的自定义目录 /usr/local/rpm 会自动创建)
[root@redhat8 ~]# dnf -y --enablerepo=mysql80-community install mysql-community-server --downloadonly --downloaddir=/usr/local/rpm

备注:
假如MySQL8.0已经安装了,以上这句命令就等于失效了,不会再次下载软件包的;
以本地光盘作为Yum源时,也是可以下载软件包到指定目录的;



下载完成后,查看目录大小:
[root@redhat8 ~]# du -sh /usr/local/rpm/
84M     /usr/local/rpm/

查看目录里的文件数量:( 实际数量=N-1 )
[root@redhat8 ~]# ll /usr/local/rpm/ |wc -l
48


通过安装本地RPM软件包,从而实现MySQL8.0的安装:(此时可以使用本地光盘作为Yum源)
[root@redhat8 ~]# dnf -y install /usr/local/rpm/*.rpm


MySQL8.0安装成功:
[root@redhat8 ~]# yum list |grep mysql
mysql-community-client.x86_64                        8.0.26-1.el8                                     @@commandline
mysql-community-client-plugins.x86_64                8.0.26-1.el8                                     @@commandline
mysql-community-common.x86_64                        8.0.26-1.el8                                     @@commandline
mysql-community-libs.x86_64                          8.0.26-1.el8                                     @@commandline
mysql-community-server.x86_64                        8.0.26-1.el8                                     @@commandline
apr-util-mysql.x86_64                                1.6.1-6.el8                                      localREPO_APP
dovecot-mysql.x86_64                                 1:2.3.8-2.el8                                    localREPO_APP
freeradius-mysql.x86_64                              3.0.17-7.module_el8.2.0+321+f9fd5d26             localREPO_APP
grafana-mysql.x86_64                                 6.3.6-1.el8                                      localREPO_APP
pcp-pmda-mysql.x86_64                                5.0.2-5.el8                                      localREPO_APP
php-mysqlnd.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             localREPO_APP
postfix-mysql.x86_64                                 2:3.3.1-12.el8                                   localREPO_APP
qt5-qtbase-mysql.i686                                5.12.5-4.el8                                     localREPO_APP
qt5-qtbase-mysql.x86_64                              5.12.5-4.el8                                     localREPO_APP
rsyslog-mysql.x86_64                                 8.1911.0-3.el8                                   localREPO_APP
rubygem-mysql2.x86_64                                0.4.10-4.module_el8.1.0+214+9be47fd7             localREPO_APP
rubygem-mysql2-doc.noarch                            0.4.10-4.module_el8.1.0+214+9be47fd7             localREPO_APP

注释:第三列前面有 @ 代表已经安装了。


安装后,目录/usr/local/rpm/里的软件包会被自动删除的:
图片1.png
2021-9-2 17:09



启动MySQL:
[root@redhat8 ~]# systemctl start mysqld

开机自动启动MySQL:
[root@redhat8 ~]# systemctl enable mysqld

确认开机会自动启动MySQL:
[root@redhat8 ~]# systemctl is-enabled mysqld
enabled


查看MySQL的版本:
[root@redhat8 ~]# mysql -V
mysql  Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)



查看MySQL的进程:
[root@redhat8 ~]# systemctl stop mysqld

[root@redhat8 ~]# ps -ef |grep mysqld |grep -v grep
[root@redhat8 ~]#
[root@redhat8 ~]# echo $?
1


[root@redhat8 ~]# systemctl start mysqld

[root@redhat8 ~]# ps -ef |grep mysqld |grep -v grep
mysql      12345       1 13 10:24 ?        00:00:00 /usr/sbin/mysqld
[root@redhat8 ~]# echo $?
0



MySQL的主配置文件:(初始状态)
[root@redhat8 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid



自定义MySQL的主配置文件:
[root@redhat8 ~]# cat /etc/my.cnf
[client]
#password   = your_password
port        = 3306
socket      = /var/lib/mysql/mysql.sock

[mysqld]
port        = 3306
socket      = /var/lib/mysql/mysql.sock
datadir = /var/lib/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
tmp_table_size = 16M
performance_schema_max_table_instances = 500

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
default_authentication_plugin = mysql_native_password

log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
binlog_expire_logs_seconds = 864000
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_buffer_pool_size = 16M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer_size = 2M
write_buffer_size = 2M

[mysqlhotcopy]
interactive-timeout



根据服务器的物理内存大小更改MySQL的主配置文件的脚本:
[root@redhat8 ~]# cat change.sh
  1. #!/bin/bash

  2. MySQL_Opt()
  3. {
  4. MemTotal=`free -m | grep Mem | awk '{print  $2}'`

  5.     if [[ ${MemTotal} -gt 1024 && ${MemTotal} -lt 2048 ]]; then
  6.         sed -i "s#^key_buffer_size.*#key_buffer_size = 32M#" /etc/my.cnf
  7.         sed -i "s#^table_open_cache.*#table_open_cache = 128#" /etc/my.cnf
  8.         sed -i "s#^sort_buffer_size.*#sort_buffer_size = 768K#" /etc/my.cnf
  9.         sed -i "s#^read_buffer_size.*#read_buffer_size = 768K#" /etc/my.cnf
  10.         sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 8M#" /etc/my.cnf
  11.         sed -i "s#^thread_cache_size.*#thread_cache_size = 16#" /etc/my.cnf
  12.         sed -i "s#^query_cache_size.*#query_cache_size = 16M#" /etc/my.cnf
  13.         sed -i "s#^tmp_table_size.*#tmp_table_size = 32M#" /etc/my.cnf
  14.         sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 128M#" /etc/my.cnf
  15.         sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 32M#" /etc/my.cnf
  16.         sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 1000#" /etc/my.cnf
  17.     elif [[ ${MemTotal} -ge 2048 && ${MemTotal} -lt 4096 ]]; then
  18.         sed -i "s#^key_buffer_size.*#key_buffer_size = 64M#" /etc/my.cnf
  19.         sed -i "s#^table_open_cache.*#table_open_cache = 256#" /etc/my.cnf
  20.         sed -i "s#^sort_buffer_size.*#sort_buffer_size = 1M#" /etc/my.cnf
  21.         sed -i "s#^read_buffer_size.*#read_buffer_size = 1M#" /etc/my.cnf
  22.         sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 16M#" /etc/my.cnf
  23.         sed -i "s#^thread_cache_size.*#thread_cache_size = 32#" /etc/my.cnf
  24.         sed -i "s#^query_cache_size.*#query_cache_size = 32M#" /etc/my.cnf
  25.         sed -i "s#^tmp_table_size.*#tmp_table_size = 64M#" /etc/my.cnf
  26.         sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 256M#" /etc/my.cnf
  27.         sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 64M#" /etc/my.cnf
  28.         sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 2000#" /etc/my.cnf
  29.     elif [[ ${MemTotal} -ge 4096 && ${MemTotal} -lt 8192 ]]; then
  30.         sed -i "s#^key_buffer_size.*#key_buffer_size = 128M#" /etc/my.cnf
  31.         sed -i "s#^table_open_cache.*#table_open_cache = 512#" /etc/my.cnf
  32.         sed -i "s#^sort_buffer_size.*#sort_buffer_size = 2M#" /etc/my.cnf
  33.         sed -i "s#^read_buffer_size.*#read_buffer_size = 2M#" /etc/my.cnf
  34.         sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 32M#" /etc/my.cnf
  35.         sed -i "s#^thread_cache_size.*#thread_cache_size = 64#" /etc/my.cnf
  36.         sed -i "s#^query_cache_size.*#query_cache_size = 64M#" /etc/my.cnf
  37.         sed -i "s#^tmp_table_size.*#tmp_table_size = 64M#" /etc/my.cnf
  38.         sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 512M#" /etc/my.cnf
  39.         sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 128M#" /etc/my.cnf
  40.         sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 4000#" /etc/my.cnf
  41.     elif [[ ${MemTotal} -ge 8192 && ${MemTotal} -lt 16384 ]]; then
  42.         sed -i "s#^key_buffer_size.*#key_buffer_size = 256M#" /etc/my.cnf
  43.         sed -i "s#^table_open_cache.*#table_open_cache = 1024#" /etc/my.cnf
  44.         sed -i "s#^sort_buffer_size.*#sort_buffer_size = 4M#" /etc/my.cnf
  45.         sed -i "s#^read_buffer_size.*#read_buffer_size = 4M#" /etc/my.cnf
  46.         sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 64M#" /etc/my.cnf
  47.         sed -i "s#^thread_cache_size.*#thread_cache_size = 128#" /etc/my.cnf
  48.         sed -i "s#^query_cache_size.*#query_cache_size = 128M#" /etc/my.cnf
  49.         sed -i "s#^tmp_table_size.*#tmp_table_size = 128M#" /etc/my.cnf
  50.         sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 1024M#" /etc/my.cnf
  51.         sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 256M#" /etc/my.cnf
  52.         sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 6000#" /etc/my.cnf
  53.     elif [[ ${MemTotal} -ge 16384 && ${MemTotal} -lt 32768 ]]; then
  54.         sed -i "s#^key_buffer_size.*#key_buffer_size = 512M#" /etc/my.cnf
  55.         sed -i "s#^table_open_cache.*#table_open_cache = 2048#" /etc/my.cnf
  56.         sed -i "s#^sort_buffer_size.*#sort_buffer_size = 8M#" /etc/my.cnf
  57.         sed -i "s#^read_buffer_size.*#read_buffer_size = 8M#" /etc/my.cnf
  58.         sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 128M#" /etc/my.cnf
  59.         sed -i "s#^thread_cache_size.*#thread_cache_size = 256#" /etc/my.cnf
  60.         sed -i "s#^query_cache_size.*#query_cache_size = 256M#" /etc/my.cnf
  61.         sed -i "s#^tmp_table_size.*#tmp_table_size = 256M#" /etc/my.cnf
  62.         sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 2048M#" /etc/my.cnf
  63.         sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 512M#" /etc/my.cnf
  64.         sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 8000#" /etc/my.cnf
  65.     elif [[ ${MemTotal} -ge 32768 ]]; then
  66.         sed -i "s#^key_buffer_size.*#key_buffer_size = 1024M#" /etc/my.cnf
  67.         sed -i "s#^table_open_cache.*#table_open_cache = 4096#" /etc/my.cnf
  68.         sed -i "s#^sort_buffer_size.*#sort_buffer_size = 16M#" /etc/my.cnf
  69.         sed -i "s#^read_buffer_size.*#read_buffer_size = 16M#" /etc/my.cnf
  70.         sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 256M#" /etc/my.cnf
  71.         sed -i "s#^thread_cache_size.*#thread_cache_size = 512#" /etc/my.cnf
  72.         sed -i "s#^query_cache_size.*#query_cache_size = 512M#" /etc/my.cnf
  73.         sed -i "s#^tmp_table_size.*#tmp_table_size = 512M#" /etc/my.cnf
  74.         sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 4096M#" /etc/my.cnf
  75.         sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 1024M#" /etc/my.cnf
  76.         sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 10000#" /etc/my.cnf
  77.     fi
  78. }
  79. MySQL_Opt
复制代码




运行脚本:
[root@redhat8 ~]# bash change.sh


再次查看MySQL的主配置文件:
[root@redhat8 ~]# cat /etc/my.cnf
[client]
#password   = your_password
port        = 3306
socket      = /var/lib/mysql/mysql.sock

[mysqld]
port        = 3306
socket      = /var/lib/mysql/mysql.sock
datadir = /var/lib/mysql
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
tmp_table_size = 32M
performance_schema_max_table_instances = 1000

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
default_authentication_plugin = mysql_native_password

log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
binlog_expire_logs_seconds = 864000
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer_size = 768K
write_buffer_size = 2M

[mysqlhotcopy]
interactive-timeout



重启MySQL:
[root@redhat8 ~]# systemctl restart mysqld



获取数据库管理员root@localhost的初始密码:
[root@centos8 ~]# cat /var/log/mysqld.log |grep 'A temporary password'
2021-09-01T02:21:10.185122Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: oM1xgNgQte#+


服务器本地登录MySQL:
mysql -u"root" -p"oM1xgNgQte#+"
图片2.png
2021-9-2 17:16



必须要修改数据库管理员root@localhost的密码:(密码要符合复杂性要求)
mysql> ALTER USER root@'localhost' IDENTIFIED BY 'P@ssw7rd';
Query OK, 0 rows affected (0.01 sec)


数据库管理员root@localhost使用新密码重新登录MySQL:
mysql -uroot -p"P@ssw7rd"
图片3.png
2021-9-2 17:17



查看默认的用户密码策略:
SHOW VARIABLES LIKE 'validate_password%';
图片4.png
2021-9-2 17:17



默认就有的库:
show databases;
图片5.png
2021-9-2 17:18



查看所有数据库用户及其主机信息:(以下是初始状态)
select user,host from mysql.user;
图片6.png
2021-9-2 17:18



查看数据库管理员root@localhost的权限:
mysql> show grants for root@localhost;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION                                                                                                                                                                                                                    |
| GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,XA_RECOVER_ADMIN ON *.* TO `root`@`localhost` WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)



查看MySQL的最大连接数:
show variables like '%max_connection%';
图片7.png
2021-9-2 17:19



查看MySQL的“最大可打开表数”:(能同时打开的表的总数量)
show variables like 'table_open%';
图片8.png
2021-9-2 17:19



查看MySQL的默认存储引擎:
show variables like '%storage_engine%';
图片9.png
2021-9-2 17:20



查看MySQL的默认字符集:
show variables like '%character%';
图片10.png
2021-9-2 17:20


show variables like '%collation%';
图片11.png
2021-9-2 17:20




下面,修改数据库的默认字符集为 utf8mb4_unicode_ci

修改MySQL的主配置文件:
[root@redhat8 ~]# cat /etc/my.cnf
[client]
#password   = your_password
port        = 3306
socket      = /var/lib/mysql/mysql.sock

[mysqld]
port        = 3306
socket      = /var/lib/mysql/mysql.sock
datadir = /var/lib/mysql
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
tmp_table_size = 32M
performance_schema_max_table_instances = 1000

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
default_authentication_plugin = mysql_native_password

log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
binlog_expire_logs_seconds = 864000
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci


[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer_size = 768K
write_buffer_size = 2M

[mysqlhotcopy]
interactive-timeout


重启MySQL:
[root@redhat8 ~]# systemctl restart mysqld


修改数据库的默认字符集成功:
mysql -u"root" -p"P@ssw7rd" -e"show variables like '%character%';"
图片12.png
2021-9-2 17:22


mysql -u"root" -p"P@ssw7rd" -e "show variables like '%collation%';"
图片13.png
2021-9-2 17:22




新建的库的默认字符集为 utf8mb4_unicode_ci
[root@redhat8 ~]# mysql -u"root" -p"P@ssw7rd" -e"create database db1;"
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@redhat8 ~]# mysql -u"root" -p"P@ssw7rd" -e"show create database db1"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------+-------------------------------------------------------------------------------------------------------------------------------+
| Database | Create Database                                                                                                               |
+----------+-------------------------------------------------------------------------------------------------------------------------------+
| db1      | CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ /*!80016 DEFAULT ENCRYPTION='N' */ |
+----------+-------------------------------------------------------------------------------------------------------------------------------+





相关文章:
MySQL的字符集
Shell脚本中的函数

MySQL8.0使用Jemalloc
使用Navicat远程管理MySQL8.0

CentOS8_重置MySQL8.0的用户密码
忽略Linux下MySQL8.0的表名的英文字母大小写

MySQL8.0使用mysql_config_editor
CentOS8使用Python3脚本管理MySQL8.0

CentOS8_在Docker中安装LAMP(使用参数--link)

CentOS8_Yum安装MySQL5.7
CentOS8_Tomcat8+JDK1.8+MySQL

CentOS8_Postfix+Dovecot+SquirrelMail
CentOS8使用CentOS-Vault源+EPEL
CentOS8使用mailx(使用126邮箱的25端口)

返回列表