Linux数据库安装

简介: 本文介绍了在CentOS 8.0和Ubuntu 22.04系统上安装、配置和启动MariaDB数据库服务器的详细步骤。包括通过`yum`和`apt`包管理器安装MariaDB服务,启动并检查服务运行状态,设置root用户密码以及连接数据库的基本操作。此外,还展示了如何在Ubuntu上更新软件包列表、安装依赖项,并验证MariaDB的版本和运行状态。通过这些步骤,用户可以成功部署并初始化MariaDB环境,为后续数据库管理与应用开发奠定基础。

系统环境

CentOS 8.0 64位

  1. 安装MariaDB Server

     # 安装MariaDB Server
     yum install -y mariadb-server
    
     Failed to set locale, defaulting to C
     Last metadata expiration check: 0:56:20 ago on Mon Apr 28 09:15:28 2025.
     Dependencies resolved.
     ==================================================================================
      Package           Arch   Version                                 Repository
                                                                                  Size
     ==================================================================================
     Installing:
      mariadb-server    x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream  16 M
     Installing dependencies:
      mariadb           x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream 6.0 M
      mariadb-common    x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream  64 k
      mariadb-connector-c
                        x86_64 3.1.11-2.el8_3                          AppStream 200 k
      mariadb-connector-c-config
                        noarch 3.1.11-2.el8_3                          AppStream  15 k
      mariadb-errmsg    x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream 234 k
      perl-DBD-MySQL    x86_64 4.046-3.module_el8.3.0+419+c2dec72b     AppStream 156 k
      perl-DBI          x86_64 1.641-3.module_el8.3.0+413+9be2aeb5     AppStream 740 k
      perl-Digest       noarch 1.17-395.el8                            AppStream  27 k
      perl-Digest-MD5   x86_64 2.55-396.el8                            AppStream  37 k
      perl-Net-SSLeay   x86_64 1.88-1.module_el8.3.0+410+ff426aa3      AppStream 379 k
      perl-URI          noarch 1.73-3.el8                              AppStream 116 k
      perl-libnet       noarch 3.11-3.el8                              AppStream 121 k
      perl-Data-Dumper  x86_64 2.167-399.el8                           BaseOS     58 k
      perl-Encode       x86_64 4:2.97-3.el8                            BaseOS    1.5 M
      perl-File-Temp    noarch 0.230.600-1.el8                         BaseOS     63 k
      perl-Getopt-Long  noarch 1:2.50-4.el8                            BaseOS     63 k
      perl-HTTP-Tiny    noarch 0.074-1.el8                             BaseOS     58 k
      perl-MIME-Base64  x86_64 3.15-396.el8                            BaseOS     31 k
      perl-Math-BigInt  noarch 1:1.9998.11-7.el8                       BaseOS    196 k
      perl-Math-Complex noarch 1.59-420.el8                            BaseOS    108 k
      perl-Pod-Escapes  noarch 1:1.07-395.el8                          BaseOS     20 k
      perl-Pod-Perldoc  noarch 3.28-396.el8                            BaseOS     86 k
      perl-Pod-Simple   noarch 1:3.35-395.el8                          BaseOS    213 k
      perl-Pod-Usage    noarch 4:1.69-395.el8                          BaseOS     34 k
      perl-Storable     x86_64 1:3.11-3.el8                            BaseOS     98 k
      perl-Term-ANSIColor
                        noarch 4.06-396.el8                            BaseOS     46 k
      perl-Term-Cap     noarch 1.17-395.el8                            BaseOS     23 k
      perl-Text-ParseWords
                        noarch 3.30-395.el8                            BaseOS     18 k
      perl-Time-Local   noarch 1:1.280-1.el8                           BaseOS     34 k
      perl-podlators    noarch 4.11-1.el8                              BaseOS    118 k
     Installing weak dependencies:
      mariadb-backup    x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream 6.1 M
      mariadb-gssapi-server
                        x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream  51 k
      mariadb-server-utils
                        x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d AppStream 1.1 M
      perl-IO-Socket-IP noarch 0.39-5.el8                              AppStream  47 k
      perl-IO-Socket-SSL
                        noarch 2.066-4.module_el8.3.0+410+ff426aa3     AppStream 298 k
      perl-Mozilla-CA   noarch 20160104-7.module_el8.3.0+416+dee7bcef  AppStream  15 k
     Enabling module streams:
      mariadb                  10.3                                                   
      perl-DBD-MySQL           4.046                                                  
      perl-DBI                 1.641                                                  
      perl-IO-Socket-SSL
                               2.066                                                  
      perl-libwww-perl         6.34                                                   
    
     Transaction Summary
     ==================================================================================
     Install  37 Packages
    
     Total download size: 35 M
     Installed size: 170 M
     Downloading Packages:
     (1/37): mariadb-common-10.3.28-1.module_el8.3.0+7 186 kB/s |  64 kB     00:00    
     (2/37): mariadb-10.3.28-1.module_el8.3.0+757+d382 9.7 MB/s | 6.0 MB     00:00    
     (3/37): mariadb-connector-c-3.1.11-2.el8_3.x86_64 478 kB/s | 200 kB     00:00    
     (4/37): mariadb-connector-c-config-3.1.11-2.el8_3 103 kB/s |  15 kB     00:00    
     (5/37): mariadb-gssapi-server-10.3.28-1.module_el 204 kB/s |  51 kB     00:00    
     (6/37): mariadb-errmsg-10.3.28-1.module_el8.3.0+7 848 kB/s | 234 kB     00:00    
     (7/37): mariadb-server-utils-10.3.28-1.module_el8 2.8 MB/s | 1.1 MB     00:00    
     (8/37): perl-DBD-MySQL-4.046-3.module_el8.3.0+419 634 kB/s | 156 kB     00:00    
     (9/37): perl-DBI-1.641-3.module_el8.3.0+413+9be2a 2.1 MB/s | 740 kB     00:00    
     (10/37): perl-Digest-1.17-395.el8.noarch.rpm      164 kB/s |  27 kB     00:00    
     (11/37): mariadb-server-10.3.28-1.module_el8.3.0+  13 MB/s |  16 MB     00:01    
     (12/37): perl-Digest-MD5-2.55-396.el8.x86_64.rpm  372 kB/s |  37 kB     00:00    
     (13/37): perl-IO-Socket-SSL-2.066-4.module_el8.3. 1.1 MB/s | 298 kB     00:00    
     (14/37): perl-IO-Socket-IP-0.39-5.el8.noarch.rpm  177 kB/s |  47 kB     00:00    
     (15/37): perl-Mozilla-CA-20160104-7.module_el8.3.  66 kB/s |  15 kB     00:00    
     (16/37): perl-Net-SSLeay-1.88-1.module_el8.3.0+41 956 kB/s | 379 kB     00:00    
     (17/37): perl-URI-1.73-3.el8.noarch.rpm           335 kB/s | 116 kB     00:00    
     (18/37): perl-libnet-3.11-3.el8.noarch.rpm        339 kB/s | 121 kB     00:00    
     (19/37): perl-Data-Dumper-2.167-399.el8.x86_64.rp 221 kB/s |  58 kB     00:00    
     (20/37): perl-Encode-2.97-3.el8.x86_64.rpm         13 MB/s | 1.5 MB     00:00    
     (21/37): perl-File-Temp-0.230.600-1.el8.noarch.rp 317 kB/s |  63 kB     00:00    
     (22/37): perl-Getopt-Long-2.50-4.el8.noarch.rpm   247 kB/s |  63 kB     00:00    
     (23/37): perl-HTTP-Tiny-0.074-1.el8.noarch.rpm    238 kB/s |  58 kB     00:00    
     (24/37): perl-MIME-Base64-3.15-396.el8.x86_64.rpm 164 kB/s |  31 kB     00:00    
     (25/37): perl-Math-Complex-1.59-420.el8.noarch.rp 437 kB/s | 108 kB     00:00    
     (26/37): perl-Pod-Escapes-1.07-395.el8.noarch.rpm 270 kB/s |  20 kB     00:00    
     (27/37): perl-Math-BigInt-1.9998.11-7.el8.noarch. 410 kB/s | 196 kB     00:00    
     (28/37): perl-Pod-Perldoc-3.28-396.el8.noarch.rpm 319 kB/s |  86 kB     00:00    
     (29/37): perl-Pod-Simple-3.35-395.el8.noarch.rpm  718 kB/s | 213 kB     00:00    
     (30/37): perl-Pod-Usage-1.69-395.el8.noarch.rpm   199 kB/s |  34 kB     00:00    
     (31/37): perl-Storable-3.11-3.el8.x86_64.rpm      653 kB/s |  98 kB     00:00    
     (32/37): perl-Term-ANSIColor-4.06-396.el8.noarch. 179 kB/s |  46 kB     00:00    
     (33/37): perl-Term-Cap-1.17-395.el8.noarch.rpm     81 kB/s |  23 kB     00:00    
     (34/37): perl-Text-ParseWords-3.30-395.el8.noarch  79 kB/s |  18 kB     00:00    
     (35/37): perl-Time-Local-1.280-1.el8.noarch.rpm   245 kB/s |  34 kB     00:00    
     (36/37): perl-podlators-4.11-1.el8.noarch.rpm     1.7 MB/s | 118 kB     00:00    
     (37/37): mariadb-backup-10.3.28-1.module_el8.3.0+ 840 kB/s | 6.1 MB     00:07    
     ----------------------------------------------------------------------------------
     Total                                             4.7 MB/s |  35 MB     00:07     
     Running transaction check
     Transaction check succeeded.
     Running transaction test
     Transaction test succeeded.
     Running transaction
       Preparing        :                                                          1/1 
       Installing       : perl-MIME-Base64-3.15-396.el8.x86_64                    1/37 
       Installing       : perl-File-Temp-0.230.600-1.el8.noarch                   2/37 
       Installing       : perl-Data-Dumper-2.167-399.el8.x86_64                   3/37 
       Installing       : perl-IO-Socket-IP-0.39-5.el8.noarch                     4/37 
       Installing       : mariadb-connector-c-config-3.1.11-2.el8_3.noarch        5/37 
       Installing       : mariadb-common-3:10.3.28-1.module_el8.3.0+757+d38299    6/37 
       Installing       : perl-Time-Local-1:1.280-1.el8.noarch                    7/37 
       Installing       : perl-Text-ParseWords-3.30-395.el8.noarch                8/37 
       Installing       : perl-Storable-1:3.11-3.el8.x86_64                       9/37 
       Installing       : mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d38299   10/37 
       Installing       : perl-Digest-1.17-395.el8.noarch                        11/37 
       Installing       : perl-Digest-MD5-2.55-396.el8.x86_64                    12/37 
       Installing       : perl-Net-SSLeay-1.88-1.module_el8.3.0+410+ff426aa3.x   13/37 
       Installing       : perl-Term-Cap-1.17-395.el8.noarch                      14/37 
       Installing       : perl-Term-ANSIColor-4.06-396.el8.noarch                15/37 
       Installing       : perl-Pod-Escapes-1:1.07-395.el8.noarch                 16/37 
       Installing       : perl-Math-Complex-1.59-420.el8.noarch                  17/37 
       Installing       : perl-Math-BigInt-1:1.9998.11-7.el8.noarch              18/37 
       Installing       : perl-Mozilla-CA-20160104-7.module_el8.3.0+416+dee7bc   19/37 
       Installing       : perl-Encode-4:2.97-3.el8.x86_64                        20/37 
       Installing       : perl-Pod-Simple-1:3.35-395.el8.noarch                  21/37 
       Installing       : perl-Getopt-Long-1:2.50-4.el8.noarch                   22/37 
       Installing       : perl-podlators-4.11-1.el8.noarch                       23/37 
       Installing       : perl-Pod-Usage-4:1.69-395.el8.noarch                   24/37 
       Installing       : perl-Pod-Perldoc-3.28-396.el8.noarch                   25/37 
       Installing       : perl-HTTP-Tiny-0.074-1.el8.noarch                      26/37 
       Installing       : perl-IO-Socket-SSL-2.066-4.module_el8.3.0+410+ff426a   27/37 
       Installing       : perl-libnet-3.11-3.el8.noarch                          28/37 
       Installing       : perl-URI-1.73-3.el8.noarch                             29/37 
       Installing       : perl-DBI-1.641-3.module_el8.3.0+413+9be2aeb5.x86_64    30/37 
       Installing       : perl-DBD-MySQL-4.046-3.module_el8.3.0+419+c2dec72b.x   31/37 
       Installing       : mariadb-connector-c-3.1.11-2.el8_3.x86_64              32/37 
       Installing       : mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d38299   33/37 
       Installing       : mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757   34/37 
       Installing       : mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+   35/37 
       Running scriptlet: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299   36/37 
       Installing       : mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299   36/37 
       Running scriptlet: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299   36/37 
       Installing       : mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_   37/37 
       Running scriptlet: mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_   37/37 
       Verifying        : mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_    1/37 
       Verifying        : mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d38299    2/37 
       Verifying        : mariadb-common-3:10.3.28-1.module_el8.3.0+757+d38299    3/37 
       Verifying        : mariadb-connector-c-3.1.11-2.el8_3.x86_64               4/37 
       Verifying        : mariadb-connector-c-config-3.1.11-2.el8_3.noarch        5/37 
       Verifying        : mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d38299    6/37 
       Verifying        : mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757    7/37 
       Verifying        : mariadb-server-3:10.3.28-1.module_el8.3.0+757+d38299    8/37 
       Verifying        : mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+    9/37 
       Verifying        : perl-DBD-MySQL-4.046-3.module_el8.3.0+419+c2dec72b.x   10/37 
       Verifying        : perl-DBI-1.641-3.module_el8.3.0+413+9be2aeb5.x86_64    11/37 
       Verifying        : perl-Digest-1.17-395.el8.noarch                        12/37 
       Verifying        : perl-Digest-MD5-2.55-396.el8.x86_64                    13/37 
       Verifying        : perl-IO-Socket-IP-0.39-5.el8.noarch                    14/37 
       Verifying        : perl-IO-Socket-SSL-2.066-4.module_el8.3.0+410+ff426a   15/37 
       Verifying        : perl-Mozilla-CA-20160104-7.module_el8.3.0+416+dee7bc   16/37 
       Verifying        : perl-Net-SSLeay-1.88-1.module_el8.3.0+410+ff426aa3.x   17/37 
       Verifying        : perl-URI-1.73-3.el8.noarch                             18/37 
       Verifying        : perl-libnet-3.11-3.el8.noarch                          19/37 
       Verifying        : perl-Data-Dumper-2.167-399.el8.x86_64                  20/37 
       Verifying        : perl-Encode-4:2.97-3.el8.x86_64                        21/37 
       Verifying        : perl-File-Temp-0.230.600-1.el8.noarch                  22/37 
       Verifying        : perl-Getopt-Long-1:2.50-4.el8.noarch                   23/37 
       Verifying        : perl-HTTP-Tiny-0.074-1.el8.noarch                      24/37 
       Verifying        : perl-MIME-Base64-3.15-396.el8.x86_64                   25/37 
       Verifying        : perl-Math-BigInt-1:1.9998.11-7.el8.noarch              26/37 
       Verifying        : perl-Math-Complex-1.59-420.el8.noarch                  27/37 
       Verifying        : perl-Pod-Escapes-1:1.07-395.el8.noarch                 28/37 
       Verifying        : perl-Pod-Perldoc-3.28-396.el8.noarch                   29/37 
       Verifying        : perl-Pod-Simple-1:3.35-395.el8.noarch                  30/37 
       Verifying        : perl-Pod-Usage-4:1.69-395.el8.noarch                   31/37 
       Verifying        : perl-Storable-1:3.11-3.el8.x86_64                      32/37 
       Verifying        : perl-Term-ANSIColor-4.06-396.el8.noarch                33/37 
       Verifying        : perl-Term-Cap-1.17-395.el8.noarch                      34/37 
       Verifying        : perl-Text-ParseWords-3.30-395.el8.noarch               35/37 
       Verifying        : perl-Time-Local-1:1.280-1.el8.noarch                   36/37 
       Verifying        : perl-podlators-4.11-1.el8.noarch                       37/37 
    
     Installed:
       mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                   
       mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                   
       mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64            
       mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64             
       perl-IO-Socket-IP-0.39-5.el8.noarch                                             
       perl-IO-Socket-SSL-2.066-4.module_el8.3.0+410+ff426aa3.noarch                   
       perl-Mozilla-CA-20160104-7.module_el8.3.0+416+dee7bcef.noarch                   
       mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                          
       mariadb-common-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                   
       mariadb-connector-c-3.1.11-2.el8_3.x86_64                                       
       mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                
       mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                   
       perl-DBD-MySQL-4.046-3.module_el8.3.0+419+c2dec72b.x86_64                       
       perl-DBI-1.641-3.module_el8.3.0+413+9be2aeb5.x86_64                             
       perl-Digest-1.17-395.el8.noarch                                                 
       perl-Digest-MD5-2.55-396.el8.x86_64                                             
       perl-Net-SSLeay-1.88-1.module_el8.3.0+410+ff426aa3.x86_64                       
       perl-URI-1.73-3.el8.noarch                                                      
       perl-libnet-3.11-3.el8.noarch                                                   
       perl-Data-Dumper-2.167-399.el8.x86_64                                           
       perl-Encode-4:2.97-3.el8.x86_64                                                 
       perl-File-Temp-0.230.600-1.el8.noarch                                           
       perl-Getopt-Long-1:2.50-4.el8.noarch                                            
       perl-HTTP-Tiny-0.074-1.el8.noarch                                               
       perl-MIME-Base64-3.15-396.el8.x86_64                                            
       perl-Math-BigInt-1:1.9998.11-7.el8.noarch                                       
       perl-Math-Complex-1.59-420.el8.noarch                                           
       perl-Pod-Escapes-1:1.07-395.el8.noarch                                          
       perl-Pod-Perldoc-3.28-396.el8.noarch                                            
       perl-Pod-Simple-1:3.35-395.el8.noarch                                           
       perl-Pod-Usage-4:1.69-395.el8.noarch                                            
       perl-Storable-1:3.11-3.el8.x86_64                                               
       perl-Term-ANSIColor-4.06-396.el8.noarch                                         
       perl-Term-Cap-1.17-395.el8.noarch                                               
       perl-Text-ParseWords-3.30-395.el8.noarch                                        
       perl-Time-Local-1:1.280-1.el8.noarch                                            
       perl-podlators-4.11-1.el8.noarch                                                
    
     Complete!
    
  2. 启动MariaDB Server

     # 启动MariaDB Server
     systemctl start mariadb
    
  3. 查看MariaDB Server运行状态

     # 查看MariaDB Server运行状态
     systemctl status mariadb
    
     ● mariadb.service - MariaDB 10.3 database server
        Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor pres>
        Active: active (running) since Mon 2025-04-28 10:15:00 CST; 21s ago
          Docs: man:mysqld(8)
                https://mariadb.com/kb/en/library/systemd/
       Process: 2192 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, stat>
       Process: 2058 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (c>
       Process: 2033 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status>
      Main PID: 2160 (mysqld)
        Status: "Taking your SQL requests now..."
         Tasks: 30 (limit: 4693)
        Memory: 80.8M
        CGroup: /system.slice/mariadb.service
                └─2160 /usr/libexec/mysqld --basedir=/usr
    
     Apr 28 10:15:00 kij106 mysql-prepare-db-dir[2058]: Please report any problems at >
     Apr 28 10:15:00 kij106 mysql-prepare-db-dir[2058]: The latest information about M>
     Apr 28 10:15:00 kij106 mysql-prepare-db-dir[2058]: You can find additional inform>
     Apr 28 10:15:00 kij106 mysql-prepare-db-dir[2058]: http://dev.mysql.com
     Apr 28 10:15:00 kij106 mysql-prepare-db-dir[2058]: Consider joining MariaDB's str>
     Apr 28 10:15:00 kij106 mysql-prepare-db-dir[2058]: https://mariadb.org/get-involv>
     Apr 28 10:15:00 kij106 mysqld[2160]: 2025-04-28 10:15:00 0 [Note] /usr/libexec/my>
     Apr 28 10:15:00 kij106 mysqld[2160]: 2025-04-28 10:15:00 0 [Warning] Could not in>
     Apr 28 10:15:00 kij106 mysqld[2160]: 2025-04-28 10:15:00 0 [Warning] Changed limi>
     Apr 28 10:15:00 kij106 systemd[1]: Started MariaDB 10.3 database server.
    
  4. 设置数据库root用户的初始密码

     # 设置数据库root用户的初始密码
     mysqladmin -u root -p password #空格后面直接输入密码 然后按回车Enter ,没加密码 出现如下内容
    
     [root@kij106 ~]# mysqladmin -u root -p password
     Enter password: 
     mysqladmin: connect to server at 'localhost' failed
     error: 'Access denied for user 'root'@'localhost' (using password: YES)'
    
     root@kij106:~#  mysqladmin -u root -p password
     Enter password: # 直接回车输入 然后输入新密码
     New password: 
     Confirm new password:
    
  1. 连接数据库

     # 连接数据库
     mysql -uroot -p
    
     [root@kij106 ~]# mysql -uroot -p
     Enter password: 
     Welcome to the MariaDB monitor.  Commands end with ; or \g.
     Your MariaDB connection id is 10
     Server version: 10.3.28-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.
    
     MariaDB [(none)]> show databases;
     +--------------------+
     | Database           |
     +--------------------+
     | information_schema |
     | mysql              |
     | performance_schema |
     +--------------------+
     3 rows in set (0.000 sec)
    
     MariaDB [(none)]> exit;
     Bye
    

Ubuntu 22.04 64位

  1. 更新apt

     apt list --upgradable
    
  2. 安装MariaDB所需软件包

    sudo apt-get install wget software-properties-common dirmngr ca-certificates apt-transport-https -y
    
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    ca-certificates is already the newest version (20240203~22.04.1).
    dirmngr is already the newest version (2.2.27-3ubuntu2.3).
    software-properties-common is already the newest version (0.99.22.9).
    wget is already the newest version (1.21.2-2ubuntu1.1).
    apt-transport-https is already the newest version (2.4.13).
    0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
    
  3. 安装MariaDB

    sudo apt install mariadb-server mariadb-client
    
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    The following additional packages will be installed:
      galera-4 libcgi-fast-perl libcgi-pm-perl libclone-perl libconfig-inifiles-perl
      libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-bin libfcgi-perl
      libfcgi0ldbl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
      libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
      libmariadb3 libtimedate-perl liburi-perl liburing2 mariadb-client-10.6
      mariadb-client-core-10.6 mariadb-common mariadb-server-10.6
      mariadb-server-core-10.6 socat
    Suggested packages:
      libmldbm-perl libnet-daemon-perl libsql-statement-perl libdata-dump-perl
      libipc-sharedcache-perl libbusiness-isbn-perl libwww-perl mariadb-test
    The following NEW packages will be installed:
      galera-4 libcgi-fast-perl libcgi-pm-perl libclone-perl libconfig-inifiles-perl
      libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-bin libfcgi-perl
      libfcgi0ldbl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
      libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
      libmariadb3 libtimedate-perl liburi-perl liburing2 mariadb-client
      mariadb-client-10.6 mariadb-client-core-10.6 mariadb-common mariadb-server
      mariadb-server-10.6 mariadb-server-core-10.6 socat
    0 upgraded, 30 newly installed, 0 to remove and 12 not upgraded.
    Need to get 17.7 MB of archives.
    After this operation, 161 MB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 mariadb-common all 1:10.6.21-0ubuntu0.22.04.2 [17.0 kB]
    Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/universe amd64 galera-4 amd64 26.4.9-1build1 [720 kB]
    Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libdbi-perl amd64 1.643-3build3 [741 kB]
    Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libconfig-inifiles-perl all 3.000003-1 [40.5 kB]
    Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 libmariadb3 amd64 1:10.6.21-0ubuntu0.22.04.2 [189 kB]
    Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 mariadb-client-core-10.6 amd64 1:10.6.21-0ubuntu0.22.04.2 [1,002 kB]
    Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 mariadb-client-10.6 amd64 1:10.6.21-0ubuntu0.22.04.2 [1,632 kB]
    Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 liburing2 amd64 2.1-2build1 [10.3 kB]
    Get:9 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 mariadb-server-core-10.6 amd64 1:10.6.21-0ubuntu0.22.04.2 [8,067 kB]
    Get:10 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 socat amd64 1.7.4.1-3ubuntu4 [349 kB]
    Get:11 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 mariadb-server-10.6 amd64 1:10.6.21-0ubuntu0.22.04.2 [4,143 kB]
    Get:12 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libhtml-tagset-perl all 3.20-4 [12.5 kB]
    Get:13 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 liburi-perl all 5.10-1 [78.8 kB]
    Get:14 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libhtml-parser-perl amd64 3.76-1build2 [88.4 kB]
    Get:15 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libcgi-pm-perl all 4.54-1 [188 kB]
    Get:16 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libfcgi0ldbl amd64 2.4.2-2build2 [28.0 kB]
    Get:17 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libfcgi-perl amd64 0.82+ds-1build1 [22.8 kB]
    Get:18 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libcgi-fast-perl all 1:2.15-1 [10.5 kB]
    Get:19 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libclone-perl amd64 0.45-1build3 [11.0 kB]
    Get:20 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 libdbd-mysql-perl amd64 4.050-5ubuntu0.22.04.1 [87.6 kB]
    Get:21 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libencode-locale-perl all 1.05-1.1 [11.8 kB]
    Get:22 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libfcgi-bin amd64 2.4.2-2build2 [11.2 kB]
    Get:23 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libhtml-template-perl all 2.97-1.1 [59.1 kB]
    Get:24 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libtimedate-perl all 2.3300-2 [34.0 kB]
    Get:25 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libhttp-date-perl all 6.05-1 [9,920 B]
    Get:26 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libio-html-perl all 1.004-2 [15.4 kB]
    Get:27 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 liblwp-mediatypes-perl all 6.04-1 [19.5 kB]
    Get:28 http://mirrors.cloud.aliyuncs.com/ubuntu jammy/main amd64 libhttp-message-perl all 6.36-1 [76.8 kB]
    Get:29 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 mariadb-client all 1:10.6.21-0ubuntu0.22.04.2 [13.1 kB]
    Get:30 http://mirrors.cloud.aliyuncs.com/ubuntu jammy-updates/universe amd64 mariadb-server all 1:10.6.21-0ubuntu0.22.04.2 [11.8 kB]
    Fetched 17.7 MB in 5s (3,530 kB/s)          
    Preconfiguring packages ...
    Selecting previously unselected package mariadb-common.
    (Reading database ... 82364 files and directories currently installed.)
    Preparing to unpack .../0-mariadb-common_1%3a10.6.21-0ubuntu0.22.04.2_all.deb ...
    Unpacking mariadb-common (1:10.6.21-0ubuntu0.22.04.2) ...
    Selecting previously unselected package galera-4.
    Preparing to unpack .../1-galera-4_26.4.9-1build1_amd64.deb ...
    Unpacking galera-4 (26.4.9-1build1) ...
    Selecting previously unselected package libdbi-perl:amd64.
    Preparing to unpack .../2-libdbi-perl_1.643-3build3_amd64.deb ...
    Unpacking libdbi-perl:amd64 (1.643-3build3) ...
    Selecting previously unselected package libconfig-inifiles-perl.
    Preparing to unpack .../3-libconfig-inifiles-perl_3.000003-1_all.deb ...
    Unpacking libconfig-inifiles-perl (3.000003-1) ...
    Selecting previously unselected package libmariadb3:amd64.
    Preparing to unpack .../4-libmariadb3_1%3a10.6.21-0ubuntu0.22.04.2_amd64.deb ...
    Unpacking libmariadb3:amd64 (1:10.6.21-0ubuntu0.22.04.2) ...
    Selecting previously unselected package mariadb-client-core-10.6.
    Preparing to unpack .../5-mariadb-client-core-10.6_1%3a10.6.21-0ubuntu0.22.04.2_amd64.deb ...
    Unpacking mariadb-client-core-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Selecting previously unselected package mariadb-client-10.6.
    Preparing to unpack .../6-mariadb-client-10.6_1%3a10.6.21-0ubuntu0.22.04.2_amd64.deb ...
    Unpacking mariadb-client-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Selecting previously unselected package liburing2:amd64.
    Preparing to unpack .../7-liburing2_2.1-2build1_amd64.deb ...
    Unpacking liburing2:amd64 (2.1-2build1) ...
    Selecting previously unselected package mariadb-server-core-10.6.
    Preparing to unpack .../8-mariadb-server-core-10.6_1%3a10.6.21-0ubuntu0.22.04.2_amd64.deb ...
    Unpacking mariadb-server-core-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Selecting previously unselected package socat.
    Preparing to unpack .../9-socat_1.7.4.1-3ubuntu4_amd64.deb ...
    Unpacking socat (1.7.4.1-3ubuntu4) ...
    Setting up mariadb-common (1:10.6.21-0ubuntu0.22.04.2) ...
    update-alternatives: using /etc/mysql/mariadb.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
    Selecting previously unselected package mariadb-server-10.6.
    (Reading database ... 82788 files and directories currently installed.)
    Preparing to unpack .../00-mariadb-server-10.6_1%3a10.6.21-0ubuntu0.22.04.2_amd64.deb ...
    Unpacking mariadb-server-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Selecting previously unselected package libhtml-tagset-perl.
    Preparing to unpack .../01-libhtml-tagset-perl_3.20-4_all.deb ...
    Unpacking libhtml-tagset-perl (3.20-4) ...
    Selecting previously unselected package liburi-perl.
    Preparing to unpack .../02-liburi-perl_5.10-1_all.deb ...
    Unpacking liburi-perl (5.10-1) ...
    Selecting previously unselected package libhtml-parser-perl:amd64.
    Preparing to unpack .../03-libhtml-parser-perl_3.76-1build2_amd64.deb ...
    Unpacking libhtml-parser-perl:amd64 (3.76-1build2) ...
    Selecting previously unselected package libcgi-pm-perl.
    Preparing to unpack .../04-libcgi-pm-perl_4.54-1_all.deb ...
    Unpacking libcgi-pm-perl (4.54-1) ...
    Selecting previously unselected package libfcgi0ldbl:amd64.
    Preparing to unpack .../05-libfcgi0ldbl_2.4.2-2build2_amd64.deb ...
    Unpacking libfcgi0ldbl:amd64 (2.4.2-2build2) ...
    Selecting previously unselected package libfcgi-perl:amd64.
    Preparing to unpack .../06-libfcgi-perl_0.82+ds-1build1_amd64.deb ...
    Unpacking libfcgi-perl:amd64 (0.82+ds-1build1) ...
    Selecting previously unselected package libcgi-fast-perl.
    Preparing to unpack .../07-libcgi-fast-perl_1%3a2.15-1_all.deb ...
    Unpacking libcgi-fast-perl (1:2.15-1) ...
    Selecting previously unselected package libclone-perl.
    Preparing to unpack .../08-libclone-perl_0.45-1build3_amd64.deb ...
    Unpacking libclone-perl (0.45-1build3) ...
    Selecting previously unselected package libdbd-mysql-perl:amd64.
    Preparing to unpack .../09-libdbd-mysql-perl_4.050-5ubuntu0.22.04.1_amd64.deb ...
    Unpacking libdbd-mysql-perl:amd64 (4.050-5ubuntu0.22.04.1) ...
    Selecting previously unselected package libencode-locale-perl.
    Preparing to unpack .../10-libencode-locale-perl_1.05-1.1_all.deb ...
    Unpacking libencode-locale-perl (1.05-1.1) ...
    Selecting previously unselected package libfcgi-bin.
    Preparing to unpack .../11-libfcgi-bin_2.4.2-2build2_amd64.deb ...
    Unpacking libfcgi-bin (2.4.2-2build2) ...
    Selecting previously unselected package libhtml-template-perl.
    Preparing to unpack .../12-libhtml-template-perl_2.97-1.1_all.deb ...
    Unpacking libhtml-template-perl (2.97-1.1) ...
    Selecting previously unselected package libtimedate-perl.
    Preparing to unpack .../13-libtimedate-perl_2.3300-2_all.deb ...
    Unpacking libtimedate-perl (2.3300-2) ...
    Selecting previously unselected package libhttp-date-perl.
    Preparing to unpack .../14-libhttp-date-perl_6.05-1_all.deb ...
    Unpacking libhttp-date-perl (6.05-1) ...
    Selecting previously unselected package libio-html-perl.
    Preparing to unpack .../15-libio-html-perl_1.004-2_all.deb ...
    Unpacking libio-html-perl (1.004-2) ...
    Selecting previously unselected package liblwp-mediatypes-perl.
    Preparing to unpack .../16-liblwp-mediatypes-perl_6.04-1_all.deb ...
    Unpacking liblwp-mediatypes-perl (6.04-1) ...
    Selecting previously unselected package libhttp-message-perl.
    Preparing to unpack .../17-libhttp-message-perl_6.36-1_all.deb ...
    Unpacking libhttp-message-perl (6.36-1) ...
    Selecting previously unselected package mariadb-client.
    Preparing to unpack .../18-mariadb-client_1%3a10.6.21-0ubuntu0.22.04.2_all.deb ...
    Unpacking mariadb-client (1:10.6.21-0ubuntu0.22.04.2) ...
    Selecting previously unselected package mariadb-server.
    Preparing to unpack .../19-mariadb-server_1%3a10.6.21-0ubuntu0.22.04.2_all.deb ...
    Unpacking mariadb-server (1:10.6.21-0ubuntu0.22.04.2) ...
    Setting up libconfig-inifiles-perl (3.000003-1) ...
    Setting up galera-4 (26.4.9-1build1) ...
    Setting up libfcgi0ldbl:amd64 (2.4.2-2build2) ...
    Setting up libclone-perl (0.45-1build3) ...
    Setting up libhtml-tagset-perl (3.20-4) ...
    Setting up liblwp-mediatypes-perl (6.04-1) ...
    Setting up libfcgi-bin (2.4.2-2build2) ...
    Setting up libencode-locale-perl (1.05-1.1) ...
    Setting up socat (1.7.4.1-3ubuntu4) ...
    Setting up libio-html-perl (1.004-2) ...
    Setting up libmariadb3:amd64 (1:10.6.21-0ubuntu0.22.04.2) ...
    Setting up libtimedate-perl (2.3300-2) ...
    Setting up libfcgi-perl:amd64 (0.82+ds-1build1) ...
    Setting up liburing2:amd64 (2.1-2build1) ...
    Setting up liburi-perl (5.10-1) ...
    Setting up libdbi-perl:amd64 (1.643-3build3) ...
    Setting up mariadb-server-core-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Setting up libhttp-date-perl (6.05-1) ...
    Setting up mariadb-client-core-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Setting up libdbd-mysql-perl:amd64 (4.050-5ubuntu0.22.04.1) ...
    Setting up libhtml-parser-perl:amd64 (3.76-1build2) ...
    Setting up mariadb-client-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Setting up libhttp-message-perl (6.36-1) ...
    Setting up mariadb-client (1:10.6.21-0ubuntu0.22.04.2) ...
    Setting up libcgi-pm-perl (4.54-1) ...
    Setting up libhtml-template-perl (2.97-1.1) ...
    Setting up mariadb-server-10.6 (1:10.6.21-0ubuntu0.22.04.2) ...
    Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /lib/systemd/system/mariadb.service.
    Setting up libcgi-fast-perl (1:2.15-1) ...
    Setting up mariadb-server (1:10.6.21-0ubuntu0.22.04.2) ...
    Processing triggers for man-db (2.10.2-1) ...
    Processing triggers for libc-bin (2.35-0ubuntu3.9) ...
    Scanning processes...                                                             
    Scanning candidates...                                                            
    Scanning linux images...                                                          
    
    Running kernel seems to be up-to-date.
    
    Restarting services...
    Service restarts being deferred:
     /etc/needrestart/restart.d/dbus.service
     systemctl restart networkd-dispatcher.service
     systemctl restart unattended-upgrades.service
    
    No containers need to be restarted.
    
    No user sessions are running outdated binaries.
    
    No VM guests are running outdated hypervisor (qemu) binaries on this host.
    
  4. 查看版本信息

    mariadb --version
    
    mariadb  Ver 15.1 Distrib 10.6.21-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
    
  5. 查看运行状态

    systemctl status mariadb
    
    ● mariadb.service - MariaDB 10.6.21 database server
         Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset:>
         Active: active (running) since Mon 2025-04-28 13:07:28 CST; 2min 57s ago
           Docs: man:mariadbd(8)
                 https://mariadb.com/kb/en/library/systemd/
        Process: 7010 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/r>
        Process: 7013 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_STAR>
        Process: 7026 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VA>
        Process: 7067 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_STA>
        Process: 7069 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SU>
       Main PID: 7055 (mariadbd)
         Status: "Taking your SQL requests now..."
          Tasks: 8 (limit: 6350)
         Memory: 76.2M
            CPU: 475ms
         CGroup: /system.slice/mariadb.service
                 └─7055 /usr/sbin/mariadbd
    
    Apr 28 13:07:28 kij106 mariadbd[7055]: 2025-04-28 13:07:28 0 [Note] /usr/sbin/mar>
    Apr 28 13:07:28 kij106 mariadbd[7055]: Version: '10.6.21-MariaDB-0ubuntu0.22.04.2>
    Apr 28 13:07:28 kij106 systemd[1]: Started MariaDB 10.6.21 database server.
    Apr 28 13:07:28 kij106 /etc/mysql/debian-start[7074]: Looking for 'mariadb' as: />
    Apr 28 13:07:28 kij106 /etc/mysql/debian-start[7074]: Looking for 'mariadb-check'>
    Apr 28 13:07:28 kij106 /etc/mysql/debian-start[7074]: This installation of MariaD>
    Apr 28 13:07:28 kij106 /etc/mysql/debian-start[7074]: There is no need to run mys>
    lines 1-25
    
  1. 设置密码同上
目录
相关文章
|
13天前
|
Java 关系型数据库 MySQL
在Linux平台上进行JDK、Tomcat、MySQL的安装并部署后端项目
现在,你可以通过访问http://Your_IP:Tomcat_Port/Your_Project访问你的项目了。如果一切顺利,你将看到那绚烂的胜利之光照耀在你的项目之上!
94 41
|
11天前
|
SQL 关系型数据库 MySQL
MySQL下载安装全攻略!小白也能轻松上手,从此数据库不再难搞!
这是一份详细的MySQL安装与配置教程,适合初学者快速上手。内容涵盖从下载到安装的每一步操作,包括选择版本、设置路径、配置端口及密码等。同时提供基础操作指南,如数据库管理、数据表增删改查、用户权限设置等。还介绍了备份恢复、图形化工具使用和性能优化技巧,帮助用户全面掌握MySQL的使用方法。附带常见问题解决方法,保姆级教学让你无忧入门!
MySQL下载安装全攻略!小白也能轻松上手,从此数据库不再难搞!
|
5天前
|
开发框架 Java 关系型数据库
在Linux系统中安装JDK、Tomcat、MySQL以及部署J2EE后端接口
校验时,浏览器输入:http://[your_server_IP]:8080/myapp。如果你看到你的应用的欢迎页面,恭喜你,一切都已就绪。
122 17
|
3天前
|
关系型数据库 MySQL Java
安装和配置JDK、Tomcat、MySQL环境,以及如何在Linux下更改后端端口。
遵循这些步骤,你可以顺利完成JDK、Tomcat、MySQL环境的安装和配置,并在Linux下更改后端端口。祝你顺利!
47 11
|
10天前
|
消息中间件 NoSQL Linux
Redis的基本介绍和安装方式(包括Linux和Windows版本),以及常用命令的演示
Redis(Remote Dictionary Server)是一个高性能的开源键值存储数据库。它支持字符串、列表、散列、集合等多种数据类型,具有持久化、发布/订阅等高级功能。由于其出色的性能和广泛的使用场景,Redis在应用程序中常作为高速缓存、消息队列等用途。
110 16
|
1月前
|
Ubuntu Linux 编译器
在Ubuntu Linux系统下如何搭建并安装EDK2
以上就是在Ubuntu Linux系统下搭建并安装EDK2的过程。这个过程可能会有些复杂,但只要按照步骤一步步来,应该不会有太大问题。如果在过程中遇到任何问题,都可以在网上找到相应的解决方案。希望这个指南能对你有所帮助!
96 17
|
1月前
|
Oracle 关系型数据库 MySQL
Oracle linux 8 二进制安装 MySQL 8.4企业版
Oracle linux 8 二进制安装 MySQL 8.4企业版
61 1
|
1月前
|
监控 Java Shell
【YashanDB 知识库】ycm 托管数据库时,数据库非 OM 安装无法托管
本文主要介绍了因数据库未按规范使用 yasboot 安装导致的问题及解决方法。问题表现为无 yasom 和 yasagent 进程,且目录结构缺失,致使 ycm 无法托管与监控。分析发现可能是数据库版本旧或安装不规范引起。解决方法为先生成配置文件,安装 yasom 和 yasagent,再生成并修改托管配置模板,最终通过命令完成托管至 yasom 和 ycm。总结强调了按规范安装数据库的重要性以避免类似问题。
|
1月前
|
安全 Java Linux
Linux安装Elasticsearch详细教程
Linux安装Elasticsearch详细教程
95 1
|
网络协议 关系型数据库 MySQL
Linux (centos8)安装 MySQL 8 数据库(图文详细教程)
本教程手把手教你如何在 Linux 安装 MySQL 数据库,以 CentOS 7为例。
585 0