CentOS7 安裝MariaDB

來源:互聯網
上載者:User

標籤:

      MariaDB資料庫管理系統是MySQL的一個分支。開發這個分支的原因之一是:甲骨文公司收購了MySQL後,有將MySQL閉源的潛在風險,因此社區採用分支的方式來避開這個風險。MariaDB的目的是完全相容MySQL,包括API和命令列,使之能輕鬆成為MySQL的代替品。一些如Google、維基、LinkedIn、Mozilla等的頂級的網站已經遷移到MariaDB了

  安裝MySQL,發現是CentOS 7 版本將MySQL資料庫軟體從預設的程式列表中移除,用mariadb代替。毫不客氣,折騰小海獅。

  系統內容:

[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) 

  安裝mariadb server和用戶端:

[[email protected] ~]# yum install mariadb-server mariadb

  等待安裝完成即可。開啟mariadb server,並設定開機自啟動。

[[email protected] ~]# systemctl start mariadb.service[[email protected] ~]# systemctl enable mariadb.serviceln -s ‘/usr/lib/systemd/system/mariadb.service‘ ‘/etc/systemd/system/multi-user.target.wants/mariadb.service‘

  MariaDB Server預設root密碼為空白,重設root密碼有兩種方法,一種是傳統方法,登入mysql修改密碼,一種是用mysql_secure_installation。

  方法1:

  登入mariadb,進入mysql資料庫,更新密碼

 

[[email protected] ~]# mysql -u rootMariaDB [(none)]> use mysql;MariaDB [mysql]> update user set password=PASSWORD(“密碼寫在這”) where User=’root’;

     需用flush privileges重新整理MySQL的系統許可權相關表,否則會出現拒絕訪問。quit退出,重新登入。

MariaDB [mysql]> flush privileges;MariaDB [mysql]> quit使用新密碼重新登入[[email protected] ~]# mysql -u root -p

 方法2:

[[email protected] ~]# mysql_secure_installation/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we‘ll need the currentpassword for the root user.  If you‘ve just installed MariaDB, andyou haven‘t set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none): //密碼為空白,直接斷行符號OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n] y     //是否設定root密碼New password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y    //清楚匿名使用者 ... Success!Normally, root should only be allowed to connect from ‘localhost‘.  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n   //不允許root遠端連線 ... skipping.By default, MariaDB comes with a database named ‘test‘ that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y  //刪除test資料庫 - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y  //重新載入許可權表 ... Success!Cleaning up...All done!  If you‘ve completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!

  OK,現在重新進入

[[email protected] ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 12Server version: 5.5.44-MariaDB MariaDB ServerCopyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.MariaDB [(none)]> 

  還有重要的一步,設定允許遠端使用者訪問。

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;Query OK, 0 rows affected (0.01 sec)MariaDB [(none)]> flush privileges;Query OK, 0 rows affected (0.00 sec)

  "%"表示任何主機都可以遠程登入到該伺服器上訪問。如果要限制只有某台機器可以訪問,將其換成相應的IP即可

     開啟3306連接埠。centos7啟用了firewalld替代了原來的iptables。既然新事物出現,一定有它出現的理由。

[[email protected] ~]# systemctl start firewalld                    //啟動firewalld服務
[[email protected] ~]# firewall-cmd --state
running

[[email protected] ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent    //開啟連接埠

success

[[email protected] ~]# firewall-cmd --reload
success

命令含義: --zone #範圍 --add-port=80/tcp  #添加連接埠,格式為:連接埠/通訊協議 --permanent   #永久生效,沒有此參數重啟後失效 重啟防火牆

 

確認一下確實開啟了連接埠:

[[email protected] ~]# netstat -ntlp | grep 3306tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2911/mysqld         

 

 

BINGO!繼續折騰

CentOS7 安裝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.