在CentOS下安裝MariaDB

來源:互聯網
上載者:User

標籤:java   centos   db   

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庫檔案:

[[email protected] /]# vi  /etc/yum.repos.d/MariaDB.repo

將從網站上複製的內容(如上)添加到空檔案中並儲存,自此MariaDB的yum庫建立好了。

1.2、安裝

通過yum進行安裝,執行如下命令,即可安裝服務端和用戶端:

[[email protected] /]# yum install –y  MariaDB-server MariaDB-client

安裝完成後,可以啟動MariaDB:

[[email protected] /]# systemctl start  mariadb.service

設定開機自動啟動:

[[email protected] /]# systemctl enable  mariadb.service

1.3、開啟防火牆

外部存取MariaDB,比如Java等連結,需要通過3306連接埠,因此需要開放3306連接埠:

[[email protected] /]# firewall-cmd --permanent  --zone=public --add-port=3306/tcp

success

其中permanent 參數將防火牆設定為永久的。

1.4、查看資料庫

初始安裝後,可以查看預設的資料庫,瞭解安裝是否成功,此時需要進入mariaDB資料庫的控制台中進行查看。

剛安裝好後,直接進入控制台不需要任何許可權:

[[email protected] /]# 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

[[email protected] /]#

此時當再次登陸時,需要指定登入使用者,以及可以直接輸入密碼:

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,則後期會要求輸入密碼:

[[email protected] /]# mysql -u root -p
 Enter  password:

本文出自 “千年之約” 部落格,謝絕轉載!

在CentOS下安裝MariaDB

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.