官网地址:https://mariadb.org/
-
在 /etc/yum.repos.d/ 目录下创建配置文件 MariaDB.repo
touch MariaDB.repo
-
进入配置文件
vim MariaDB.repo
-
配置内容
[mariadb] name = MariaDB baseurl = https://mirrors.aliyun.com/mariadb/yum/10.5/centos8-amd64/ module_hotfixes=1 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
-
执行安装命令
sudo dnf install MariaDB-server
安装过程中,会有是否下载的选择,直接 y 然后回车
Last metadata expiration check: 0:01:50 ago on Thu 08 Apr 2021 08:59:30 PM CST. Dependencies resolved. =============================================================================== Package Arch Version Repo Size =============================================================================== Installing: MariaDB-server x86_64 10.5.9-1.el8 mariadb 27 M Installing dependencies: boost-program-options x86_64 1.66.0-10.el8 AppStream 141 k perl-DBI x86_64 1.641-3.module_el8.1.0+199+8f0a6bbd AppStream 740 k socat x86_64 1.7.3.3-2.el8 AppStream 302 k perl-Math-BigInt noarch 1:1.9998.11-7.el8 BaseOS 196 k perl-Math-Complex noarch 1.59-416.el8 BaseOS 108 k MariaDB-client x86_64 10.5.9-1.el8 mariadb 13 M MariaDB-common x86_64 10.5.9-1.el8 mariadb 87 k MariaDB-shared x86_64 10.5.9-1.el8 mariadb 115 k galera-4 x86_64 26.4.7-1.el8 mariadb 12 M Enabling module streams: perl-DBI 1.641 Transaction Summary =============================================================================== Install 10 Packages Total size: 53 M Installed size: 254 M Is this ok [y/N]: y Downloading Packages: [SKIPPED] boost-program-options-1.66.0-10.el8.x86_64.rpm: Already downloaded [SKIPPED] perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64.rpm: Already downloaded [SKIPPED] socat-1.7.3.3-2.el8.x86_64.rpm: Already downloaded [SKIPPED] perl-Math-BigInt-1.9998.11-7.el8.noarch.rpm: Already downloaded [SKIPPED] perl-Math-Complex-1.59-416.el8.noarch.rpm: Already downloaded [SKIPPED] MariaDB-client-10.5.9-1.el8.x86_64.rpm: Already downloaded [SKIPPED] MariaDB-common-10.5.9-1.el8.x86_64.rpm: Already downloaded [SKIPPED] MariaDB-server-10.5.9-1.el8.x86_64.rpm: Already downloaded [SKIPPED] MariaDB-shared-10.5.9-1.el8.x86_64.rpm: Already downloaded [SKIPPED] galera-4-26.4.7-1.el8.x86_64.rpm: Already downloaded warning: /var/cache/dnf/mariadb-b7cf991130d64314/packages/MariaDB-client-10.5.9-1.el8.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 1bb943db: NOKEY MariaDB 7.0 kB/s | 8.2 kB 00:01 Importing GPG key 0x1BB943DB: Userid : "MariaDB Package Signing Key <package-signing-key@mariadb.org>" Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB From : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: MariaDB-shared-10.5.9-1.el8.x86_64 1/10 Installing : MariaDB-shared-10.5.9-1.el8.x86_64 1/10 Running scriptlet: MariaDB-shared-10.5.9-1.el8.x86_64 1/10 Running scriptlet: MariaDB-common-10.5.9-1.el8.x86_64 2/10 Installing : MariaDB-common-10.5.9-1.el8.x86_64 2/10 Running scriptlet: MariaDB-common-10.5.9-1.el8.x86_64 2/10 Running scriptlet: MariaDB-client-10.5.9-1.el8.x86_64 3/10 Installing : MariaDB-client-10.5.9-1.el8.x86_64 3/10 Running scriptlet: MariaDB-client-10.5.9-1.el8.x86_64 3/10 Installing : perl-Math-Complex-1.59-416.el8.noarch 4/10 Installing : perl-Math-BigInt-1:1.9998.11-7.el8.noarch 5/10 Installing : perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_ 6/10 Installing : socat-1.7.3.3-2.el8.x86_64 7/10 Installing : boost-program-options-1.66.0-10.el8.x86_64 8/10 Running scriptlet: boost-program-options-1.66.0-10.el8.x86_64 8/10 Running scriptlet: galera-4-26.4.7-1.el8.x86_64 9/10 Installing : galera-4-26.4.7-1.el8.x86_64 9/10 Running scriptlet: galera-4-26.4.7-1.el8.x86_64 9/10 Running scriptlet: MariaDB-server-10.5.9-1.el8.x86_64 10/10 Installing : MariaDB-server-10.5.9-1.el8.x86_64 10/10 Running scriptlet: MariaDB-server-10.5.9-1.el8.x86_64 10/10 Two all-privilege accounts were created. One is root@localhost, it has no password, but you need to be system 'root' user to connect. Use, for example, sudo mysql The second is mysql@localhost, it has no password either, but you need to be the system 'mysql' user to connect. After connecting you can set the password, if you would need to be able to connect as any of these users with a password and without sudo See the MariaDB Knowledgebase at https://mariadb.com/kb or the MySQL manual for more instructions. Please report any problems at https://mariadb.org/jira The latest information about MariaDB is available at https://mariadb.org/. You can find additional information about the MySQL part at: https://dev.mysql.com Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/ Verifying : boost-program-options-1.66.0-10.el8.x86_64 1/10 Verifying : perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_ 2/10 Verifying : socat-1.7.3.3-2.el8.x86_64 3/10 Verifying : perl-Math-BigInt-1:1.9998.11-7.el8.noarch 4/10 Verifying : perl-Math-Complex-1.59-416.el8.noarch 5/10 Verifying : MariaDB-client-10.5.9-1.el8.x86_64 6/10 Verifying : MariaDB-common-10.5.9-1.el8.x86_64 7/10 Verifying : MariaDB-server-10.5.9-1.el8.x86_64 8/10 Verifying : MariaDB-shared-10.5.9-1.el8.x86_64 9/10 Verifying : galera-4-26.4.7-1.el8.x86_64 10/10 Installed: MariaDB-server-10.5.9-1.el8.x86_64 boost-program-options-1.66.0-10.el8.x86_64 perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64 socat-1.7.3.3-2.el8.x86_64 perl-Math-BigInt-1:1.9998.11-7.el8.noarch perl-Math-Complex-1.59-416.el8.noarch MariaDB-client-10.5.9-1.el8.x86_64 MariaDB-common-10.5.9-1.el8.x86_64 MariaDB-shared-10.5.9-1.el8.x86_64 galera-4-26.4.7-1.el8.x86_64 Complete!
-
开启服务命令
sudo systemctl start mariadb
-
开机启动命令
systemctl enable mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
-
配置命令
mysql_secure_installation
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): # 输入root(mysql)的密码,初次安装默认没有,直接回车 ... Switch to unix_socket authentication [Y/n] n # 是否切换到unix套接字身份验证[Y/n] ... Change the root password? [Y/n] y #是否设置root用户密码 New password: # 新密码 Re-enter new password: # 再次输入密码 ... Remove anonymous users? [Y/n] y # 是否删除匿名用户,建议删除 ... Disallow root login remotely? [Y/n] n # 是否禁止root远程登录,建议开启 ... Remove test database and access to it? [Y/n] n # 是否删除test数据库,可以保留 ... Reload privilege tables now? [Y/n] y # 是否重新加载权限表,也可以直接回车 ... Thanks for using MariaDB! # 看到这句话证明设置成功
-
初始化 MariaDB 完成后,以 MySQL 的 root 身份登录
mysql -uroot -p密码
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 10.5.9-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
-
赋予 root 用户远程连接权限
grant all privileges on *.* to 'root'@'%' identified by '自己设置的root密码'; flush privileges;
如果不执行这一步命令,时无法通过 Navicat 等工具连接数据库的,此外服务器也需要在安全组开放 3306 端口。