{"id":7931,"date":"2021-06-11T01:29:38","date_gmt":"2021-06-11T06:29:38","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=7931"},"modified":"2021-06-11T01:29:38","modified_gmt":"2021-06-11T06:29:38","slug":"adding-mariadb-mysql-users","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=7931","title":{"rendered":"Adding MariaDB\/MySQL Users"},"content":{"rendered":"<p>Quick notes on creating a database user &#8212; MariaDB and MySQL use a combination of username and source host to determine access. This means &#8216;me&#8217;@&#8217;localhost&#8217; and &#8216;me&#8217;@&#8217;remotehost&#8217; can have different passwords and privilege sets. How do you know what the hostname is for your connection? I usually try to connect and read the host from the error message &#8212; it&#8217;ll say &#8216;someone&#8217;@&#8217;something&#8217; cannot access the database.<\/p>\n<pre># Create a user that is allowed to connect from a specific host\r\ncreate user 'username'@'hostname' identified by 'S0m3P@s5w0rd';\r\nGRANT ALL PRIVILEGES ON dbname.* TO 'username'@'hostname';\r\n\r\n# Create a user that is allowed to connect from a specific IP\r\ncreate user 'username1'@'10.5.1.2' identified by 'S0m3P@s5w0rd';\r\nGRANT ALL PRIVILEGES ON dbname.* TO 'username1'@'10.5.1.2';\r\n\r\n# Create a user that is allowed to connect from database server\r\ncreate user 'username2'@'localhost' identified by 'S0m3P@s5w0rd';\r\nGRANT ALL PRIVILEGES ON dbname.* TO 'username2'@'localhost';\r\n\r\n# Create a user that is allowed to connect from any host\r\ncreate user 'username3'@'%' identified by 'S0m3P@s5w0rd';\r\nGRANT ALL PRIVILEGES ON dbname.* TO 'username3'@'%';\r\n\r\n# Flush so new privileges are effective\r\nflush privileges;\r\n\r\n# View list of database users\r\nSELECT User, Host FROM mysql.user;\r\n+----------------+------------+\r\n| User           | Host       |\r\n+----------------+------------+\r\n| username3      | %          |\r\n| username2      | 10.5.1.2   |\r\n| username       | hostname   |\r\n| root           | 127.0.0.1  |\r\n| root           | ::1        |\r\n| root           | localhost  |\r\n+----------------+------------+\r\n6 rows in set (0.000 sec)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Quick notes on creating a database user &#8212; MariaDB and MySQL use a combination of username and source host to determine access. This means &#8216;me&#8217;@&#8217;localhost&#8217; and &#8216;me&#8217;@&#8217;remotehost&#8217; can have different passwords and privilege sets. How do you know what the hostname is for your connection? I usually try to connect and read the host from &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1003,1391],"tags":[953,804,1392],"class_list":["post-7931","post","type-post","status-publish","format-standard","hentry","category-database","category-mariadb","tag-database","tag-mariadb","tag-users"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/7931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7931"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/7931\/revisions"}],"predecessor-version":[{"id":7932,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/7931\/revisions\/7932"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}