Loading

【软件安装】CentOS7安装Maria DB教程

背景

Maria Db是流行的跨平台MySQL数据库管理系统的分支,被认为是MySQL 的完全替代品。Maria Db是由Sun在Sun Micro systems合并期间被Oracle收购后,于2009年由MySQL的一位原始开发人员创建的。今天,Maria Db由Maria Db Foundation和社区贡献者维护和开发,
Maria Db将MySQL替换为Cent OS 7存储库中的默认数据库系统。虽然将MySQL安装到Cent OS 7并不困难,但是如果您只需要一个数据库,建议使用Maria Db进行官方支持,并且与其他存储库软件不兼容的可能性很小。

$ 表示系统的一般权限,不用使用root 超级管理员权限配置。

开始

要检查您的主机名:

第一个命令应显示您的短主机名,第二个命令应显示您的完全限定域名(FQDN)。


[root@VM_0_4_centos ~]# hostname --version
hostname 3.13
[root@VM_0_4_centos ~]# hostname 
VM_0_4_centos

更新您的系统:

$ sudo yum update

安装并启动MariaDB

$ sudo yum install mariadb-server


[root@VM-0-4-centos ~]#  sudo yum install mariadb-server
Last metadata expiration check: 0:04:15 ago on Mon 15 Nov 2021 06:40:52 PM CST.
Dependencies resolved.
==================================================================================================================================================================================================================
 Package                                                 Architecture                        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.1.0+203+e45423dc                                     AppStream                              156 k
 perl-DBI                                                x86_64                              1.641-3.module_el8.1.0+199+8f0a6bbd                                     AppStream                              740 k
 perl-Math-BigInt                                        noarch                              1:1.9998.11-7.el8                                                       BaseOS                                 196 k
 perl-Math-Complex                                       noarch                              1.59-419.el8_4.1                                                        BaseOS                                 109 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
Enabling module streams:
 mariadb                                                                                     10.3                                                                                                                
 perl-DBD-MySQL                                                                              4.046                                                                                                               
 perl-DBI                                                                                    1.641                                                                                                               

Transaction Summary
==================================================================================================================================================================================================================
Install  13 Packages

Total download size: 31 M
Installed size: 156 M
Is this ok [y/N]: y 
Downloading Packages:
(1/13): mariadb-common-10.3.28-1.module_el8.3.0+757+d382997d.x86_64.rpm                                                                                                           412 kB/s |  64 kB     00:00    
(2/13): mariadb-connector-c-3.1.11-2.el8_3.x86_64.rpm                                                                                                                             1.4 MB/s | 200 kB     00:00    
(3/13): mariadb-connector-c-config-3.1.11-2.el8_3.noarch.rpm                                                                                                                      325 kB/s |  15 kB     00:00    
(4/13): mariadb-errmsg-10.3.28-1.module_el8.3.0+757+d382997d.x86_64.rpm                                                                                                           2.0 MB/s | 234 kB     00:00    
(5/13): mariadb-gssapi-server-10.3.28-1.module_el8.3.0+757+d382997d.x86_64.rpm                                                                                                    1.2 MB/s |  51 kB     00:00    
(6/13): mariadb-10.3.28-1.module_el8.3.0+757+d382997d.x86_64.rpm                                                                                                                  7.0 MB/s | 6.0 MB     00:00    
(7/13): mariadb-backup-10.3.28-1.module_el8.3.0+757+d382997d.x86_64.rpm                                                                                                           6.1 MB/s | 6.1 MB     00:00    
(8/13): mariadb-server-utils-10.3.28-1.module_el8.3.0+757+d382997d.x86_64.rpm                                                                                                     8.3 MB/s | 1.1 MB     00:00    
(9/13): perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64.rpm                                                                                                             2.8 MB/s | 156 kB     00:00    
(10/13): perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64.rpm                                                                                                                  8.5 MB/s | 740 kB     00:00    
(11/13): perl-Math-BigInt-1.9998.11-7.el8.noarch.rpm                                                                                                                              3.2 MB/s | 196 kB     00:00    
(12/13): perl-Math-Complex-1.59-419.el8_4.1.noarch.rpm                                                                                                                            2.0 MB/s | 109 kB     00:00    
(13/13): mariadb-server-10.3.28-1.module_el8.3.0+757+d382997d.x86_64.rpm                                                                                                           12 MB/s |  16 MB     00:01    
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                              17 MB/s |  31 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                          1/1 
  Installing       : mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                                                                        1/13 
  Installing       : mariadb-common-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                           2/13 
  Installing       : mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                           3/13 
  Installing       : perl-Math-Complex-1.59-419.el8_4.1.noarch                                                                                                                                               4/13 
  Installing       : perl-Math-BigInt-1:1.9998.11-7.el8.noarch                                                                                                                                               5/13 
  Installing       : perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64                                                                                                                                     6/13 
  Installing       : perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64                                                                                                                               7/13 
  Installing       : mariadb-connector-c-3.1.11-2.el8_3.x86_64                                                                                                                                               8/13 
  Installing       : mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                           9/13 
  Installing       : mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                   10/13 
  Installing       : mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                    11/13 
  Running scriptlet: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                          12/13 
  Installing       : mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                          12/13 
  Running scriptlet: mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                          12/13 
  Installing       : mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                                 13/13 
  Running scriptlet: mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                                 13/13 
  Verifying        : mariadb-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                                  1/13 
  Verifying        : mariadb-backup-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                           2/13 
  Verifying        : mariadb-common-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                           3/13 
  Verifying        : mariadb-connector-c-3.1.11-2.el8_3.x86_64                                                                                                                                               4/13 
  Verifying        : mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                                                                        5/13 
  Verifying        : mariadb-errmsg-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                           6/13 
  Verifying        : mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                    7/13 
  Verifying        : mariadb-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                           8/13 
  Verifying        : mariadb-server-utils-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64                                                                                                                     9/13 
  Verifying        : perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64                                                                                                                              10/13 
  Verifying        : perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64                                                                                                                                    11/13 
  Verifying        : perl-Math-BigInt-1:1.9998.11-7.el8.noarch                                                                                                                                              12/13 
  Verifying        : perl-Math-Complex-1.59-419.el8_4.1.noarch                                                                                                                                              13/13 

Installed:
  mariadb-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-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         
  mariadb-gssapi-server-3:10.3.28-1.module_el8.3.0+757+d382997d.x86_64    mariadb-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-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64               perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64              perl-Math-BigInt-1:1.9998.11-7.el8.noarch                             
  perl-Math-Complex-1.59-419.el8_4.1.noarch                              

Complete!

启用MariaDB以在启动时启动,然后启动该服务:

$ sudo systemctl enable mariadb
$ sudo systemctl start mariadb

操作如下

[root@VM_0_4_centos ~]# sudo systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@VM_0_4_centos ~]# sudo systemctl start mariadb
[root@VM_0_4_centos ~]# systemctl status mariadb
?.mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-11-13 23:21:06 CST; 18s ago
  Process: 20713 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 20618 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 20712 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ?..20712 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           ?..20874 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.lo...

Nov 13 23:21:03 VM_0_4_centos mariadb-prepare-db-dir[20618]: MySQL manual for more instructions.
Nov 13 23:21:03 VM_0_4_centos mariadb-prepare-db-dir[20618]: Please report any problems at http://mariadb.org/jira
Nov 13 23:21:03 VM_0_4_centos mariadb-prepare-db-dir[20618]: The latest information about MariaDB is available at http://mariadb.org/.
Nov 13 23:21:03 VM_0_4_centos mariadb-prepare-db-dir[20618]: You can find additional information about the MySQL part at:
Nov 13 23:21:03 VM_0_4_centos mariadb-prepare-db-dir[20618]: http://dev.mysql.com
Nov 13 23:21:03 VM_0_4_centos mariadb-prepare-db-dir[20618]: Consider joining MariaDB's strong and vibrant community:
Nov 13 23:21:03 VM_0_4_centos mariadb-prepare-db-dir[20618]: https://mariadb.org/get-involved/
Nov 13 23:21:04 VM_0_4_centos mysqld_safe[20712]: 191113 23:21:04 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Nov 13 23:21:04 VM_0_4_centos mysqld_safe[20712]: 191113 23:21:04 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Nov 13 23:21:06 VM_0_4_centos systemd[1]: Started MariaDB database server.
[root@VM_0_4_centos ~]# 

默认情况下,MariaDB将绑定到localhost(127.0.0.1)。

注意

允许在公共IP上不受限制地访问MariaDB,但是您可以在/etc/my.cnf中通过修改bind-address参数来更改它侦听的地址。如果您决定将MariaDB绑定到公共IP,则应实施仅允许来自特定IP地址连接的防火墙规则。

安装完成之后,运行一下命令,进入数据库,默认不需要密码

$ mysql -uroot -p

查询数据库列表

$ show databses;

安装到此结束,余下是介绍如何使用配置

初始化配置,MariaDB的相关简单配置

接下来进行

$  mysql_secure_installation

首先是设置密码,会提示先输入密码 123456 # 【#全部回车就是的】

Enter current password for root (enter for none):<–初次运行直接回车

设置密码和其他配置

Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码

Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车

Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,

Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车

Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

初始化MariaDB完成,接下来测试登录,输入一下命令和密码 登录进去 123456

$ mysql -u root -p 

安结束了,运行错了重新来一遍 mysql_secure_installation

MariaDB [(none)]> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'database' at line 1
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)


操作不会请输入Help

要为MariaDB提示生成命令列表,请输入\h。然后你会看到:

 List of all MySQL commands:
   Note that all text commands must be first on line and end with ';'
   ?         (\?) Synonym for `help'.
   clear     (\c) Clear the current input statement.
   connect   (\r) Reconnect to the server. Optional arguments are db and host.
   delimiter (\d) Set statement delimiter.
   edit      (\e) Edit command with $EDITOR.
   ego       (\G) Send command to mysql server, display result vertically.
   exit      (\q) Exit mysql. Same as quit.
   go        (\g) Send command to mysql server.
   help      (\h) Display this help.
   nopager   (\n) Disable pager, print to stdout.
   notee     (\t) Don't write into outfile.
   pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
   print     (\p) Print current command.
   prompt    (\R) Change your mysql prompt.
   quit      (\q) Quit mysql.
   rehash    (\#) Rebuild completion hash.
   source    (\.) Execute an SQL script file. Takes a file name as an argument.
   status    (\s) Get status information from the server.
   system    (\!) Execute a system shell command.
   tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
   use       (\u) Use another database. Takes database name as argument.
   charset   (\C) Switch to another charset. Might be needed for processing 
           binlog with multi-byte charsets.
   warnings  (\W) Show warnings after every statement.
   nowarning (\w) Don't show warnings after every statement.
   
   For server side help, type 'help contents'
   
   MariaDB [(none)]> 

重置MariaDB Root密码

如果您忘记了root 密码,则可以重置密码。

停止当前的MariaDB服务器实例,然后使用不要求输入密码的选项重新启动它:
   sudo systemctl stop mariadb
   sudo mysqld_safe --skip-grant-tables &
使用MariaDB root帐户重新连接到MariaDB服务器:
   mysql -u root
使用以下命令重置root的密码。用强密码替换password:
   use mysql;
   update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
   flush privileges;
   exit
然后重启MariaDB:
   sudo systemctl start mariadb
posted @ 2019-11-13 23:19  家秋  阅读(651)  评论(1)    收藏  举报