查看操作系统的信息:
[root@centos8 ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
[root@centos8 ~]# uname -r
4.18.0-193.el8.x86_64
[root@centos8 ~]# hostname
centos8.zhuohua.store
[root@centos8 ~]# cat /etc/hostname
centos8.zhuohua.store
[root@centos8 ~]# ifconfig
-bash: ifconfig: 未找到命令
[root@centos8 ~]#
[root@centos8 ~]# dnf -y install net-tools
[root@centos8 ~]# ifconfig ens160 |grep netmask |awk '{print $2}'
192.168.168.154
关闭SELinux:(默认是开启的,要关闭)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
安装Nginx:(实验中都是使用本地光盘作为Yum源进行安装的)
yum -y install nginx
启动Nginx:
systemctl start nginx
systemctl enable nginx
安装MariaDB:
yum -y install mariadb-server mariadb
启动MariaDB:
systemctl start mariadb
systemctl enable mariadb
安装PHP:
dnf -y install php php-fpm php-mysqlnd php-gd php-xml php-mbstring php-json
重启防火墙firewalld服务:
[root@centos8 ~]# systemctl restart firewalld
在防火墙firewalld打开TCP 80端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
查看防火墙所有打开的端口:
[root@centos8 ~]# firewall-cmd --zone=public --list-ports
80/tcp
查看防火墙firewalld的配置文件:
[root@centos8 ~]# cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<service name="cockpit"/>
<port port="80" protocol="tcp"/>
</zone>
Nginx的版本信息:
[root@centos8 ~]# nginx -v
nginx version: nginx/1.14.1
[root@centos8 ~]# nginx -V
nginx version: nginx/1.14.1
built by gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC)
built with OpenSSL 1.1.1 FIPS 11 Sep 2018 (running with OpenSSL 1.1.1c FIPS 28 May 2019)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
在浏览器上直接访问服务器IP,理应可以看到Nginx的欢迎页(默认首页文件):
http://192.168.168.154/
Nginx默认站点的默认首页文件:
rpm -ql nginx |tail
Nginx的默认站点的根目录: /usr/share/nginx/html
Nginx的主配置文件:
[root@centos8 ~]# find / -name "nginx.conf"
/etc/nginx/nginx.conf
[root@centos8 ~]# cat /etc/nginx/nginx.conf |grep -v "^$"
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html; #默认站点的根目录
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; #默认站点加载的配置文件
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
默认站点加载的配置文件:
[root@centos8 ~]# cat /etc/nginx/default.d/php.conf
# pass the PHP scripts to FastCGI server
#
# See conf.d/php-fpm.conf for socket configuration
#
index index.php index.html index.htm; #在这里设置默认站点的默认首页文件
location ~ \.(php|phar)(/.*)?$ {
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php-fpm;
}
PHP的版本信息:
[root@centos8 ~]# php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
PHP的主配置文件:
[root@centos8 ~]# find / -name php.ini
/etc/php.ini
在命令行显示MariaDB的版本信息:(默认情况下,数据库管理员root@localhost没有密码的)
[root@centos8 ~]# mysqladmin -u"root" -s version
mysqladmin Ver 9.1 Distrib 10.3.17-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Server version 10.3.17-MariaDB
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 18 min 11 sec
Threads: 7 Questions: 2 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 11 Queries per second avg: 0.001
在命令行显示MariaDB里的全部库:(以下三个库是默认就有的)
[root@centos8 ~]# mysql -u"root" -sN -e "show databases"
information_schema
mysql
performance_schema
查看所有数据库用户及其主机信息:(以下是初始状态)
[root@centos8 ~]# mysql -u"root" -e"select user,host from mysql.user;"
+------+-----------------------+
| user | host |
+------+-----------------------+
| root | 127.0.0.1 |
| root | ::1 |
| root | centos8.zhuohua.store |
| root | localhost |
+------+-----------------------+
查看数据库管理员root@localhost的权限:
[root@centos8 ~]# mysql -u"root" -e"show grants for root@localhost;"
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
MariaDB的主配置文件:
[root@centos8 ~]# find / -name my.cnf
/etc/my.cnf
[root@centos8 ~]# cat /etc/my.cnf |grep -v "^$"
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
自定义MariaDB的主配置文件:
cat > /etc/my.cnf <<EOF
[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
query_cache_size = 8M
tmp_table_size = 16M
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
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 = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
EOF
根据服务器的物理内存大小更改MariaDB的主配置文件的脚本:
[root@centos8 ~]# cat change.sh
- #!/bin/bash
- MySQL_Opt()
- {
- MemTotal=`free -m | grep Mem | awk '{print $2}'`
- if [[ ${MemTotal} -gt 1024 && ${MemTotal} -lt 2048 ]]; then
- sed -i "s#^key_buffer_size.*#key_buffer_size = 32M#" /etc/my.cnf
- sed -i "s#^table_open_cache.*#table_open_cache = 128#" /etc/my.cnf
- sed -i "s#^sort_buffer_size.*#sort_buffer_size = 768K#" /etc/my.cnf
- sed -i "s#^read_buffer_size.*#read_buffer_size = 768K#" /etc/my.cnf
- sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 8M#" /etc/my.cnf
- sed -i "s#^thread_cache_size.*#thread_cache_size = 16#" /etc/my.cnf
- sed -i "s#^query_cache_size.*#query_cache_size = 16M#" /etc/my.cnf
- sed -i "s#^tmp_table_size.*#tmp_table_size = 32M#" /etc/my.cnf
- sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 128M#" /etc/my.cnf
- sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 32M#" /etc/my.cnf
- sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 1000#" /etc/my.cnf
- elif [[ ${MemTotal} -ge 2048 && ${MemTotal} -lt 4096 ]]; then
- sed -i "s#^key_buffer_size.*#key_buffer_size = 64M#" /etc/my.cnf
- sed -i "s#^table_open_cache.*#table_open_cache = 256#" /etc/my.cnf
- sed -i "s#^sort_buffer_size.*#sort_buffer_size = 1M#" /etc/my.cnf
- sed -i "s#^read_buffer_size.*#read_buffer_size = 1M#" /etc/my.cnf
- sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 16M#" /etc/my.cnf
- sed -i "s#^thread_cache_size.*#thread_cache_size = 32#" /etc/my.cnf
- sed -i "s#^query_cache_size.*#query_cache_size = 32M#" /etc/my.cnf
- sed -i "s#^tmp_table_size.*#tmp_table_size = 64M#" /etc/my.cnf
- sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 256M#" /etc/my.cnf
- sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 64M#" /etc/my.cnf
- sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 2000#" /etc/my.cnf
- elif [[ ${MemTotal} -ge 4096 && ${MemTotal} -lt 8192 ]]; then
- sed -i "s#^key_buffer_size.*#key_buffer_size = 128M#" /etc/my.cnf
- sed -i "s#^table_open_cache.*#table_open_cache = 512#" /etc/my.cnf
- sed -i "s#^sort_buffer_size.*#sort_buffer_size = 2M#" /etc/my.cnf
- sed -i "s#^read_buffer_size.*#read_buffer_size = 2M#" /etc/my.cnf
- sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 32M#" /etc/my.cnf
- sed -i "s#^thread_cache_size.*#thread_cache_size = 64#" /etc/my.cnf
- sed -i "s#^query_cache_size.*#query_cache_size = 64M#" /etc/my.cnf
- sed -i "s#^tmp_table_size.*#tmp_table_size = 64M#" /etc/my.cnf
- sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 512M#" /etc/my.cnf
- sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 128M#" /etc/my.cnf
- sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 4000#" /etc/my.cnf
- elif [[ ${MemTotal} -ge 8192 && ${MemTotal} -lt 16384 ]]; then
- sed -i "s#^key_buffer_size.*#key_buffer_size = 256M#" /etc/my.cnf
- sed -i "s#^table_open_cache.*#table_open_cache = 1024#" /etc/my.cnf
- sed -i "s#^sort_buffer_size.*#sort_buffer_size = 4M#" /etc/my.cnf
- sed -i "s#^read_buffer_size.*#read_buffer_size = 4M#" /etc/my.cnf
- sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 64M#" /etc/my.cnf
- sed -i "s#^thread_cache_size.*#thread_cache_size = 128#" /etc/my.cnf
- sed -i "s#^query_cache_size.*#query_cache_size = 128M#" /etc/my.cnf
- sed -i "s#^tmp_table_size.*#tmp_table_size = 128M#" /etc/my.cnf
- sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 1024M#" /etc/my.cnf
- sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 256M#" /etc/my.cnf
- sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 6000#" /etc/my.cnf
- elif [[ ${MemTotal} -ge 16384 && ${MemTotal} -lt 32768 ]]; then
- sed -i "s#^key_buffer_size.*#key_buffer_size = 512M#" /etc/my.cnf
- sed -i "s#^table_open_cache.*#table_open_cache = 2048#" /etc/my.cnf
- sed -i "s#^sort_buffer_size.*#sort_buffer_size = 8M#" /etc/my.cnf
- sed -i "s#^read_buffer_size.*#read_buffer_size = 8M#" /etc/my.cnf
- sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 128M#" /etc/my.cnf
- sed -i "s#^thread_cache_size.*#thread_cache_size = 256#" /etc/my.cnf
- sed -i "s#^query_cache_size.*#query_cache_size = 256M#" /etc/my.cnf
- sed -i "s#^tmp_table_size.*#tmp_table_size = 256M#" /etc/my.cnf
- sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 2048M#" /etc/my.cnf
- sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 512M#" /etc/my.cnf
- sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 8000#" /etc/my.cnf
- elif [[ ${MemTotal} -ge 32768 ]]; then
- sed -i "s#^key_buffer_size.*#key_buffer_size = 1024M#" /etc/my.cnf
- sed -i "s#^table_open_cache.*#table_open_cache = 4096#" /etc/my.cnf
- sed -i "s#^sort_buffer_size.*#sort_buffer_size = 16M#" /etc/my.cnf
- sed -i "s#^read_buffer_size.*#read_buffer_size = 16M#" /etc/my.cnf
- sed -i "s#^myisam_sort_buffer_size.*#myisam_sort_buffer_size = 256M#" /etc/my.cnf
- sed -i "s#^thread_cache_size.*#thread_cache_size = 512#" /etc/my.cnf
- sed -i "s#^query_cache_size.*#query_cache_size = 512M#" /etc/my.cnf
- sed -i "s#^tmp_table_size.*#tmp_table_size = 512M#" /etc/my.cnf
- sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = 4096M#" /etc/my.cnf
- sed -i "s#^innodb_log_file_size.*#innodb_log_file_size = 1024M#" /etc/my.cnf
- sed -i "s#^performance_schema_max_table_instances.*#performance_schema_max_table_instances = 10000#" /etc/my.cnf
- fi
- }
- MySQL_Opt
复制代码
运行脚本:
[root@centos8 ~]# bash change.sh
再次查看MariaDB的主配置文件:
[root@centos8 ~]# 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
query_cache_size = 16M
tmp_table_size = 32M
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
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 = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
重启MariaDB:
[root@centos8 ~]# systemctl restart mariadb
服务器本地登录MariaDB:(使用数据库管理员root@localhost)
mysql -u"root"
注释:数据库管理员root@localhost默认是没有密码的。
查看MariaDB的最大连接数:
MariaDB [(none)]> show variables like '%max_connection%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| extra_max_connections | 1 |
| max_connections | 500 |
+-----------------------+-------+
2 rows in set (0.001 sec)
查看MariaDB的“最大可打开表数”:(能同时打开的表的总数量)
MariaDB [(none)]> show variables like 'table_open%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| table_open_cache | 128 |
| table_open_cache_instances | 8 |
+----------------------------+-------+
2 rows in set (0.001 sec)
给数据库管理员root@localhost设置密码:
MariaDB [(none)]> ALTER USER root@'localhost' IDENTIFIED BY 'mima';
Query OK, 0 rows affected (0.001 sec)
现在数据库管理员root@localhost要通过密码验证才能登录MariaDB:
mysql -u"root" -p"mima"
再次在命令行显示MariaDB里的全部库:
[root@centos8 ~]# mysql -u"root" -p"mima" -sN -e "show databases;"
information_schema
mysql
performance_schema
再次查看所有数据库用户及其主机信息:
[root@centos8 ~]# mysql -u"root" -p"mima" -h"localhost" -e"select user,host from mysql.user;"
+------+-----------------------+
| user | host |
+------+-----------------------+
| root | 127.0.0.1 |
| root | ::1 |
| root | centos8.zhuohua.store |
| root | localhost |
+------+-----------------------+
注释:-h"localhost"是可以省略的。
###############
###############
phpMyAdmin(PHP语言编写的,是远程管理MySQL/MariaDB的工具)
安装phpMyAdmin:
tar -zxvf phpMyAdmin-4.4.15.6-all-languages.tar.gz -C /usr/share/nginx/html/
cd !$
mv phpMyAdmin-4.4.15.6-all-languages/ pmd
cd !$
mv config.sample.inc.php config.inc.php
重启Nginx:
[root@centos8 ~]# systemctl restart nginx
phpMyAdmin的配置文件:
[root@centos8 pmd]# pwd
/usr/share/nginx/html/pmd
[root@centos8 pmd]# vi config.inc.php
注释:
这里的主机地址默认为localhost,即本地连接,无需打开防火墙的TCP 3306端口;
打开防火墙的TCP 80端口,客户端就可以正常访问phpMyAdmin的管理页面了;
客户端远程登录 phpMyAdmin:(建议使用Frefox浏览器)
http://192.168.168.154/pmd/
此时,数据库的默认字符集为 latin1_swedish_ci :
使用数据库管理员root@localhost,服务器本地登录MariaDB,查看数据库的默认字符集:
show variables like "%character%";
show variables like "%collation%";
下面,修改数据库的默认字符集为 utf8mb4_unicode_ci
修改MariaDB的主配置文件:
[root@centos8 ~]# 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
query_cache_size = 16M
tmp_table_size = 32M
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
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 = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
重启MariaDB:
[root@centos8 ~]# systemctl restart mariadb
修改数据库的默认字符集成功:
[root@centos8 ~]# mysql -u"root" -p"mima" -e "show variables like '%character%';"
[root@centos8 ~]# mysql -u"root" -p"mima" -e "show variables like '%collation%';"
在phpMyAdmin也可以看到数据库的默认字符集已改为 utf8mb4_unicode_ci :
使用phpMyAdmin创建库:
注释:创建库时,不指定排序规则(字符集),就是使用默认字符集。
创建库成功:
服务器本地查看刚刚创建的库:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)
MariaDB [(none)]> show create database db1;
+----------+--------------------------------------------------------------------------------------------+
| Database | Create Database |
+----------+--------------------------------------------------------------------------------------------+
| db1 | CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ |
+----------+--------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
###############
###############
重置MariaDB的数据库管理员root@localhost的密码:(不知道密码,无法登录数据库的情况下)
确认命令都已经安装:
[root@centos8 ~]# find / -name "mysqld_safe"
/usr/bin/mysqld_safe
[root@centos8 ~]# find / -name "mysql"
/var/lib/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/perl5/vendor_perl/auto/DBD/mysql
/usr/lib64/perl5/vendor_perl/DBD/mysql
/usr/share/selinux/targeted/default/active/modules/100/mysql
关闭MariaDB:
[root@centos8 ~]# systemctl stop mariadb
跳过授权表:
[root@centos8 ~]# mysqld_safe --skip-grant-tables >/dev/null 2>&1 &
[1] 15729
现在无需密码,可以直接登录MariaDB:(不指定用户,就是使用数据库管理员root@localhost)
直接在命令行修改数据库管理员root@localhost的密码:
#先自定义新的密码
[root@centos8 ~]# mysql_root_password='123456a'
[root@centos8 ~]# echo ${mysql_root_password}
123456a
[root@centos8 ~]# mysql -u root mysql << EOF
update user set password = Password('${mysql_root_password}') where User = 'root';
EOF
如下图:
[root@centos8 ~]# killall mysqld
[root@centos8 ~]#
[1]+ 已完成 /usr/bin/mysqld_safe --skip-grant-tables > /dev/null 2>&1
启动MariaDB:
[root@centos8 ~]# systemctl start mariadb
重置MariaDB的数据库管理员root@localhost的密码成功:
mysql -u"root" -h"localhost" -p"123456a"
注释: -h"localhost" 是可以省略的。
相关文章:
CentOS8_Yum仓库
使用Navicat远程管理MariaDB
忽略Linux下MariaDB10.3的表名的英文字母大小写
CentOS8_firewalld+Nginx
CentOS8_Nginx基于域名的虚拟主机+代理虚拟主机
CentOS8_LNMP_编译安装Zabbix5.0.12
CentOS8安装LAMP+phpMyAdmin
CentOS8安装Django+Nginx反向代理
CentOS8_在Docker中安装LNMP(使用参数--link)
CentOS8_Yum安装MySQL5.7
MariaDB10.3使用Jemalloc
重置MySQL5.5/5.6/5.7的用户密码
MySQL的字符集
CentOS8_Tomcat9+JDK1.9+MySQL/MariaDB
Zabbix监控Linux下的MariaDB
CentOS8安装network服务 |