美文网首页数据库
在CentOS 7下安装MariaDB

在CentOS 7下安装MariaDB

作者: 菜心有毒 | 来源:发表于2016-09-09 13:29 被阅读983次

    1、通过yum进行安装


    1.1、初始准备

    首先需要到MariaDB网站(https://downloads.mariadb.org/),找到CentOS对应的页面,并复制如下内容(根据版本的不同,可能也会有变化):

    # MariaDB 10.1 CentOS repository list - created 2016-09-06 09:30 UTC

    # http://downloads.mariadb.org/mariadb/repositories/

    [mariadb]

    name = MariaDB

    baseurl = http://yum.mariadb.org/10.1/centos7-amd64

    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

    gpgcheck=1

    创建yum库文件:

    [root@myhost /]# vi /etc/yum.repos.d/MariaDB.repo

    将从网站上复制的内容(如上)添加到空文件中并保存,自此MariaDB的yum库建立好了。


    1.2、安装

    通过yum进行安装,执行如下命令,即可安装服务端和客户端:

    [root@myhost /]# yum install –y MariaDB-server MariaDB-client

    安装完成后,可以启动MariaDB:

    [root@myhost /]# systemctl start mariadb.service

    设置开机自动启动:

    [root@myhost /]# systemctl enable mariadb.service


    1.3、打开防火墙

    外部访问MariaDB,比如Java等链接,需要通过3306端口,因此需要开放3306端口:

    [root@myhost /]# firewall-cmd --permanent --zone=public --add-port=3306/tcp

    success

    其中permanent 参数将防火墙设置为永久的。


    1.4、查看数据库

    初始安装后,可以查看默认的数据库,了解安装是否成功,此时需要进入mariaDB数据库的控制台中进行查看。

    刚安装好后,直接进入控制台不需要任何权限:

    [root@myhost /]# mysql

    Welcome to the MariaDB monitor.  Commands end with ; or \g.

    Your MariaDB connection id is 3

    Server version: 10.1.17-MariaDB MariaDB Server

    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MariaDB [(none)]>

    此时,代表成功进入了MariaDB环境。

    可以通过如下方式查看当前所有的数据库:

    MariaDB [(none)]> show databases;

    +--------------------+

    | Database            |

    +--------------------+

    | information_schema |

    | mysql              |

    | performance_schema |

    | test                |

    +--------------------+

    4 rows in set (0.06 sec)

    MariaDB [(none)]>


    1.5、配置root用户

    root权限需要在mysql数据库中修改,因此需要先进入mysql数据库环境:

    MariaDB [(none)]> use MySQL;

    Reading table information for completion of table and column names

    You can turn off this feature to get a quicker startup with -A

    Database changed

    MariaDB [mysql]>

    进入mysql数据库环境后,为root用户更新密码,并赋予权限:

    MariaDB [mysql]> update user set password=password("xxxxxx") where user='root';

    Query OK, 0 rows affected (0.00 sec)

    Rows matched: 4 Changed: 0 Warnings: 0

    MariaDB [mysql]>

    为root用户赋予权限:

    MariaDB [mysql]> flush privileges;

    Query OK, 0 rows affected (0.00 sec)

    MariaDB [mysql]>

    最后需要退出,并重新登录:

    MariaDB [mysql]> exit

    Bye

    [root@myhost /]#

    此时当再次登陆时,需要指定登录用户,以及可以直接输入密码:

    MariaDB [mysql]> mysql -u root -p123456

    Welcome to the MariaDB monitor.  Commands end with ; or \g.

    Your MariaDB connection id is 3

    Server version: 10.1.17-MariaDB MariaDB Server

    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MariaDB [(none)]>

    p参数(密码)需要直接与密码明文拼接。

    若仅输入参数p,则后期会要求输入密码:

    [root@myhost /]# mysql -u root -p

    Enter password:

    相关文章

      网友评论

        本文标题:在CentOS 7下安装MariaDB

        本文链接:https://www.haomeiwen.com/subject/kjveettx.html