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) MariaDB [mysql]> |
爲root用戶賦予權限:
MariaDB [mysql]> flush privileges; MariaDB [mysql]> |
最後需要退出,並重新登錄:
MariaDB [mysql]> exit [root@myhost /]# |
此時當再次登陸時,需要指定登錄用戶,以及可以直接輸入密碼:
MariaDB [mysql]> mysql -u root -p123456 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 |