標籤: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