4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MariaDB に外部から接続する方法

Posted at

こちらのページを参考にしました。
Host xxx is not allowed to connect to this MySQL server の対応

次が必要です。

  1. サーバーの設定
  2. 外部から接続できるユーザーの作成
  3. サーバーの設定

    /etc/mysql/mariadb.conf.d/50-server.cnf
    (省略)
    # bind-address            = 127.0.0.1
    (省略)
    

    MariaDB の再起動

    sudo systemctl restart mariadb
    

    外部から接続できるユーザーの作成

    次の状況では、外部から接続できません。

    MariaDB [(none)]> select user, host from mysql.user;
    +-------------+-----------+
    | User        | Host      |
    +-------------+-----------+
    | mariadb.sys | localhost |
    | mysql       | localhost |
    | root        | localhost |
    | scott       | localhost |
    +-------------+-----------+
    4 rows in set (0.001 sec)
    

    次の状況では、外部から接続ができます。

    MariaDB [(none)]> select user, host from mysql.user;
    +-------------+-----------+
    | User        | Host      |
    +-------------+-----------+
    | scott       | %         |
    | mariadb.sys | localhost |
    | mysql       | localhost |
    | root        | localhost |
    | scott       | localhost |
    +-------------+-----------+
    5 rows in set (0.002 sec)
    

    ユーザーの作成方法

    CREATE USER 'scott' identified by 'tiger123';
    GRANT ALL PRIVILEGES ON *.* TO 'scott'@'%' with grant option;
    

    外部から接続

    $ mysql -uscott -ptiger123 city -h 10.39.166.1
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 36
    Server version: 10.11.2-MariaDB-1-log Ubuntu 23.04
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [city]>
    
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?