{"id":26,"date":"2017-05-11T16:20:00","date_gmt":"2017-05-11T16:20:00","guid":{"rendered":"\/colin\/morethanfour\/post\/MySQL-notes"},"modified":"2017-05-11T16:20:00","modified_gmt":"2017-05-11T16:20:00","slug":"mysql-notes","status":"publish","type":"post","link":"https:\/\/spacefold.com\/colin\/morethanfour\/2017\/05\/11\/mysql-notes\/","title":{"rendered":"MySQL notes"},"content":{"rendered":"<p>The situation is that I have a MySQL database instance somewhere out on the network. And I&#8217;m trying to connect to it.<\/p>\n<h3>Logging in from the DB host <\/h3>\n<p>Plan:<\/p>\n<ul>\n<li>Open a terminal window on the DB host, 192.168.1.130<\/li>\n<li>Attempt to connect as the root db user<\/li>\n<\/ul>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">[root@zyxx01 ~]<span style=\"color: #008000\"># mysql -u root<\/span><br>ERROR 1045 (28000): Access denied <span style=\"color: #0000ff\">for<\/span> user <span style=\"color: #006080\">'root'<\/span>@<span style=\"color: #006080\">'localhost'<\/span> (using password: NO)<\/pre>\n<p>That didn&#8217;t work. This does, though:<\/div>\n<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">[root@zyxx01 ~]<span style=\"color: #008000\"># mysql -u root -p<\/span><br>Enter password: ****<br>Welcome to the MySQL monitor. Commands <span style=\"color: #0000ff\">end<\/span> with ; or \\g.<br>Your MySQL connection id is 171310<br>Server version: 5.5.32-log MySQL Community Server (GPL)<br> <br>mysql&gt;<\/pre>\n<p><\/div>\n<p>So, don&#8217;t forget the -p option on the command-line. I guess that it tries first to connect without a password, which is a possible configuration for MySQL. And fails because it isn&#8217;t allowed in this instance.<\/p>\n<h3>Logging in from remote machine<\/h3>\n<p>My first attempt here didn&#8217;t work either, because &#8220;mysql&#8221; actually runs a batch file which expands into:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">D:\\&gt;c:\\progra~1\\mysql\\mysqls~1.5\\bin\\mysql.exe --defaults-file=c:\\ProgramData\\MySQL\\mysqls~1.5\\my.ini -uroot -p<br>Enter password: ********<br>ERROR 2003 (HY000): Can<span style=\"color: #006080\">'t connect to MySQL server on '<\/span>localhost' (10061)<\/pre>\n<p><\/div>\n<p>Invoking the .exe directly avoids that interesting &#8220;defaults-file&#8221; thing:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">D:\\&gt;c:\\progra~1\\mysql\\mysqls~1.5\\bin\\mysql.exe -h 192.168.1.130 -u root -p<br>Enter password: ********<br>Welcome to the MySQL monitor. Commands <span style=\"color: #0000ff\">end<\/span> with ; or \\g.<br>Your MySQL connection id is 204151<br>Server version: 5.5.32-log MySQL Community Server (GPL)<br> <br>Copyright (c) 2000, 2012, Oracle and\/or its affiliates. All rights reserved.<br> <br>Oracle is a registered trademark of Oracle Corporation and\/or its<br>affiliates. Other names may be trademarks of their respective<br>owners.<br> <br>Type <span style=\"color: #006080\">'help;'<\/span> or <span style=\"color: #006080\">'\\h'<\/span> <span style=\"color: #0000ff\">for<\/span> help. Type <span style=\"color: #006080\">'\\c'<\/span> to clear the current input statement.<br> <br>mysql&gt;<\/pre>\n<p><\/div>\n<p>Cool, we&#8217;re in. So now, let&#8217;s create a user:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">mysql&gt; <span style=\"color: #0000ff\">create<\/span> <span style=\"color: #0000ff\">user<\/span> <span style=\"color: #006080\">'abacab'<\/span>@<span style=\"color: #006080\">'%'<\/span> identified <span style=\"color: #0000ff\">by<\/span> <span style=\"color: #006080\">'****'<\/span>;<br>Query OK, 0 <span style=\"color: #0000ff\">rows<\/span> affected (0.00 sec)<br> <br>mysql&gt; <span style=\"color: #0000ff\">grant<\/span> <span style=\"color: #0000ff\">all<\/span> <span style=\"color: #0000ff\">privileges<\/span> <span style=\"color: #0000ff\">on<\/span> *.* <span style=\"color: #0000ff\">to<\/span> <span style=\"color: #006080\">'abacab'<\/span>@<span style=\"color: #006080\">'%'<\/span> ;<br>Query OK, 0 <span style=\"color: #0000ff\">rows<\/span> affected (0.00 sec)<br> <br>mysql&gt; flush <span style=\"color: #0000ff\">privileges<\/span>;<br>Query OK, 0 <span style=\"color: #0000ff\">rows<\/span> affected (0.00 sec)<br> <br>mysql&gt;<\/pre>\n<p><\/div>\n<p>Testing the user:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">D:\\&gt;c:\\progra~1\\mysql\\mysqls~1.5\\bin\\mysql.exe -h 192.168.1.130 -u abacab -p<br>Enter password: ***********<br>Welcome <span style=\"color: #0000ff\">to<\/span> the MySQL monitor. Commands <span style=\"color: #0000ff\">end<\/span> <span style=\"color: #0000ff\">with<\/span> ; <span style=\"color: #0000ff\">or<\/span> \\g.<br>Your MySQL <span style=\"color: #0000ff\">connection<\/span> id <span style=\"color: #0000ff\">is<\/span> 206648<br>Server version: 5.5.32-log MySQL Community Server (GPL)<br>...<br>mysql&gt;<\/pre>\n<p><\/div>\n<p>Success.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The situation is that I have a MySQL database instance somewhere out on the network. And I&#8217;m trying to connect to it. Logging in from the DB host Plan: Open a terminal window on the DB host, 192.168.1.130 Attempt to connect as the root db user [root@zyxx01 ~]# mysql -u rootERROR 1045 (28000): Access denied [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-mysql","post-preview"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}