<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MySQL | DCMST</title><link>https://portfolio.devcrumbs.com/tag/mysql/</link><atom:link href="https://portfolio.devcrumbs.com/tag/mysql/index.xml" rel="self" type="application/rss+xml"/><description>MySQL</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Wed, 30 Jul 2014 00:00:00 +0000</lastBuildDate><image><url>https://portfolio.devcrumbs.com/media/icon_hu28290437db960aa4e7d19bb9f7230401_6937_512x512_fill_lanczos_center_3.png</url><title>MySQL</title><link>https://portfolio.devcrumbs.com/tag/mysql/</link></image><item><title>MySQL reset root password</title><link>https://portfolio.devcrumbs.com/mysql-reset-root-password/</link><pubDate>Wed, 30 Jul 2014 00:00:00 +0000</pubDate><guid>https://portfolio.devcrumbs.com/mysql-reset-root-password/</guid><description>&lt;p>Hello,&lt;/p>
&lt;p>This time I share with you the faster and more secure method to reset the root password of MySQL.&lt;/p>
&lt;p>This method is faster because the downtime is between 1 or 2 seconds (MySQL restart time) and it is more secure because the mysqld is not started without grants on the tables.&lt;/p>
&lt;p>The steps are:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Create text file /var/lib/mysql/mysql-init with the sintaxis to reset the password for user root:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">vim /var/lib/mysql/mysql-init
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PASSWORD&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FOR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;root&amp;#39;&lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="s1">&amp;#39;localhost&amp;#39;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PASSWORD&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;new_password&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Add under the [mysqld] stanza on the file /etc/my.cnf:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">init-file&lt;span class="o">=&lt;/span>/var/lib/mysql/mysql-init
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Restart the mysqld service:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">service mysqld restart
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Remove the init-file line from /etc/my.cnf&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Remove /var/lib/mysql/mysql-init&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">rm /var/lib/mysql/mysql-init
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;/ol>
&lt;p>And after that, you can access again to your mysql instance.&lt;/p>
&lt;p>😄&lt;/p></description></item><item><title>MySQL without password</title><link>https://portfolio.devcrumbs.com/mysql-without-password/</link><pubDate>Tue, 15 Apr 2014 00:00:00 +0000</pubDate><guid>https://portfolio.devcrumbs.com/mysql-without-password/</guid><description>&lt;p>The common form to log in to MySQL server, is running a mysql command with your login credentials and server&amp;rsquo;s IP address as arguments. For example:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">mysql -u &lt;span class="nv">$MYSQL_ROOT&lt;/span> -p&lt;span class="nv">$MYSQL_PASS&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>However, besides the inconvenience of typing extra arguments, using plain-text login credentials in a command line like above is really not a secure way to access a MySQL server.&lt;/p>
&lt;p>MySQL offers a way for you to log in to MySQL server without password, by using an external MySQL configuration file. In Linux, there are two different kinds of MySQL configuration files:&lt;/p>
&lt;ol>
&lt;li>/etc/my.cnf and&lt;/li>
&lt;li>~/.my.conf&lt;/li>
&lt;/ol>
&lt;p>While any system-wide MySQL configuration is defined in /etc/my.cnf, any user-specific MySQL configuration is stored in ~/.my.cnf.
You can leverage ~/.my.cnf, to define your MySQL login credential in the file.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">vim ~/.my.cnf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>We put our MySQL user in the configuration file:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>client&lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">user&lt;/span>&lt;span class="o">=&lt;/span>root
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">password&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="nv">$PASSWORD_ROOT&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Make sure to have the configuration file readable to you only.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">chmod &lt;span class="m">0600&lt;/span> ~/.my.cnf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Once ~/.my.cnf is created, simply typing mysql command will let you log in to the MySQL server as root, and you no longer need to provide login password separately.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">mysql
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Welcome to the MySQL monitor. Commands end with &lt;span class="p">;&lt;/span> or &lt;span class="se">\g&lt;/span>.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Your MySQL connection id is &lt;span class="m">14787&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Server version: 5.1.73 Source distribution
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Copyright &lt;span class="o">(&lt;/span>c&lt;span class="o">)&lt;/span> 2000, 2013, Oracle and/or its affiliates. All rights reserved.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Oracle is a registered trademark of Oracle Corporation and/or its
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">affiliates. Other names may be trademarks of their respective
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">owners.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Type &lt;span class="s1">&amp;#39;help;&amp;#39;&lt;/span> or &lt;span class="s1">&amp;#39;\h&amp;#39;&lt;/span> &lt;span class="k">for&lt;/span> help. Type &lt;span class="s1">&amp;#39;\c&amp;#39;&lt;/span> to clear the current input statement.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">mysql&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item></channel></rss>