Ubuntu安裝MariaDB


默認上MariaDB的包並沒有在Ubuntu倉庫中。要安裝MariaDB,我們首先要設置MariaDB倉庫。

設置 MariaDB 倉庫

  1. $ sudo apt-get install software-properties-common
  2. $ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
  3. $ sudo add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main'

安裝 MariaDB :

  1. $ sudo apt-get update
  2. $ sudo apt-get install mariadb-server

在安裝中,你會被要求設置MariaDB的root密碼。

從命令行連接到MariaDB :

  1. linuxtechi@mail:~$ mysql -uroot -p
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is 40
  5. Server version: 10.0.14-MariaDB-1~trusty-log mariadb.org binary distribution
  6. Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MariaDB [(none)]>

MariaDB 服務

  1. $ sudo /etc/init.d/mysql stop
  2. $ sudo /etc/init.d/mysql start

 

以上只是在Ubuntu上裝完MariaDB,下面要設置MariaDB允許遠程訪問

1. 如果Ubuntu有設置防火牆或者iptables規則的話,請自行打開

 

2. 3306端口是不是沒有打開?

    使用nestat命令查看3306端口狀態:

    ~# netstat -an | grep 3306

    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN

    從結果可以看出3306端口只是在IP 127.0.0.1上監聽,所以拒絕了其他IP的訪問。

    解決方法:修改/etc/mysql/my.cnf文件。打開文件,找到下面內容:

    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address  = 127.0.0.1

    把上面這一行注釋掉或者把127.0.0.1換成合適的IP,建議注釋掉。

    重新啟動后,重新使用netstat檢測:

    ~# netstat -an | grep 3306
    tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN

 

3. 現在使用下面命令測試:

     ~# mysql -h 192.168.0.101 -u root -p
    Enter password:
    ERROR 1130 (00000): Host 'Ubuntu-Fvlo.Server' is not allowed to connect to this MySQL server

    結果出乎意料,還是不行。

    解決方法:原來還需要把用戶權限分配各遠程用戶。

    登錄到mysql服務器,使用grant命令分配權限

    mysql> grant all on *.* to 你的用戶名如root@'%' identified by '你的密碼';

    完成后使用mysql命令連接,提示成功,為了確保正確可以再遠程登陸測試一下。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM