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!
mysql 是一个指向 mariadb 的链接
1
whereis mysql
1
ls -al /usr/bin/mysql
查看 mariadb 的配置文件位置
1
mariadb --help | head -n 10
输出如下
1 2 3 4 5 6 7 8 9 10
mariadb Ver 15.1 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Usage: mariadb [OPTIONS] [database]
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf The following groups are read: mysql mariadb-client client client-server client-mariadb The following options may be given as the first argument: --print-defaults Print the program argument list and exit.
ls: cannot access '/etc/my.cnf': No such file or directory ls: cannot access '/root/.my.cnf': No such file or directory lrwxrwxrwx 1 root root 24 Oct 20 2020 /etc/mysql/my.cnf -> /etc/alternatives/my.cnf
# The MariaDB configuration file # # The MariaDB/MySQL tools read configuration files in the following order: # 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read. # 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, # 2. "/etc/mysql/conf.d/*.cnf" to set global options. # 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. # 4. "~/.my.cnf" to set user-specific options. # # If the same option is defined multiple times, the last one will apply. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/ # # This group is read both by the client and the server # use it for options that affect everything # [client-server] # Port or socket location where to connect # port = 3306 socket = /run/mysqld/mysqld.sock # Import all .cnf files from configuration directory !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mariadb.conf.d/
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; }