NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none): OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n ... skipping. //Unix socket 认证是另一种保护 MariaDB 数据库的方法。Unix socket 认证允许您在不输入密码的情况下连接到 MariaDB。相反,您使用位于服务器上的特殊套接字文件连接到 MariaDB。
//如果您不确定使用哪种方法,一般建议设置 root 用户密码并使用 mysql 客户端连接到 MariaDB。这将为您提供安全性和便利性的良好平衡。
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y //修改 root 用户密码,输入 y 并回车或直接回车 New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.
By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
Remove test database and access to it? [Y/n] y //是否删除test数据库,y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! //测试数据库包含一些示例数据,用于测试 MariaDB 功能。删除测试数据库和对它的访问权限可以帮助您防止数据被损坏。
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
All done! If you've completed all of the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB!
设置开机启动
1
sudo systemctl enable mariadb
3.3、新建数据库和用户,并进行授权
连接数据库,连接成功后,在 MariaDB [(none)]> 后输入操作命令
1
mysql -uroot -p
输出如下
1 2 3 4 5 6 7 8 9 10 11
root@iZj6cbu3y55faj33gzi8ybZ:~# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 38 Server version: 10.5.19-MariaDB-0+deb11u2 Debian 11
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# WordPress single site rules. # Designed to be included in any server {} block. # Upstream to abstract backend connection(s) for php upstream php { server unix:/run/php/php7.4-fpm.sock; }
server { listen80; server_name localhost;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html/test-www; index index.php index.html index.htm;
location / { # This is cool because no php is touched for static content. # include the "?$args" part so non-default permalinks doesn't break when using query string try_files$uri$uri/ /index.php?$args; }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html # error_page500502503504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location~ \.php$ { #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini include fastcgi_params; fastcgi_intercept_errorson; fastcgi_pass php; #The following parameter can be also included in fastcgi_params file fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
# WordPress global restrictions file
# Global restrictions configuration file. # Designed to be included in any server {} block. location = /favicon.ico { log_not_foundoff; access_logoff; }
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location~ /\. { deny all; }
# Deny access to any files with a .php extension in the uploads directory # Works in sub-directory installs and also in multisite network # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location~* /(?:uploads|files)/.*\.php$ { deny all; }
location / { # This is cool because no php is touched for static content. # include the "?$args" part so non-default permalinks doesn't break when using query string try_files$uri$uri/ /index.php?$args; }
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location~ \.php$ { #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini include fastcgi_params; fastcgi_intercept_errorson; fastcgi_pass php; #The following parameter can be also included in fastcgi_params file fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location~ /\. { deny all; }
# Deny access to any files with a .php extension in the uploads directory # Works in sub-directory installs and also in multisite network # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location~* /(?:uploads|files)/.*\.php$ { deny all; }