snipt

Ctrl+h for KB shortcuts

SQL

MySQL search and replace

1
2
3
4
5
UPDATE wp_posts SET post_content = REPLACE (
    post_content,
    'Search for this text',
    'Replace it with this'
);
https://snipt.net/embed/92db9ea402568778d5011c98e9fe1445/
https://snipt.net/raw/92db9ea402568778d5011c98e9fe1445/
92db9ea402568778d5011c98e9fe1445
sql
SQL
5
2016-09-25T02:40:27
True
False
False
Feb 16, 2016 at 12:07 PM
/api/public/snipt/144273/
mysql-search-and-replace-9c176d4e
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">UPDATE</span> <span class="n">wp_posts</span> <span class="k">SET</span> <span class="n">post_content</span> <span class="o">=</span> <span class="k">REPLACE</span> <span class="p">(</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">post_content</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="s1">&#39;Search for this text&#39;</span><span class="p">,</span> </span><span id="L-4"><a name="L-4"></a> <span class="s1">&#39;Replace it with this&#39;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">);</span> </span></pre></div> </td></tr></table>
database

Ruby

rails > get database configuration in console

Rails.configuration.database_configuration[Rails.env]
https://snipt.net/embed/90c39f5db690e5e18279fba23522d68b/
https://snipt.net/raw/90c39f5db690e5e18279fba23522d68b/
90c39f5db690e5e18279fba23522d68b
rb
Ruby
1
2016-09-25T02:40:38
True
False
False
/api/public/snipt/138105/
rails-get-database-configuration-in-console-8e5451d2
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="no">Rails</span><span class="o">.</span><span class="n">configuration</span><span class="o">.</span><span class="n">database_configuration</span><span class="o">[</span><span class="no">Rails</span><span class="o">.</span><span class="n">env</span><span class="o">]</span> </span></pre></div> </td></tr></table>
console, database, rails, ruby

Text only

Allow Remote DB connections on port 3306 for WHM

1
2
3
4
5
6
7
8
Answer From http://forums.cpanel.net/f354/whm-server-not-allowing-remote-db-connection-408421.html

WHM Server Not Allowing Remote DB Connection
I'm having trouble figuring out why our web server won't connect to Amazon RDS. I've connected via command line on a simple CentOS server and from several computers via MySQL Workbench. The RDS security groups are set up properly. The command I'm using should otherwise work. Is it possible my server is blocking outgoing connections to port 3306 and where would I change this?

- - - Updated - - -

Never mind. I should have known it would be in CSF. For anyone else who is up late at night after working all day and have a tired brain, WHM->ConfigServer Firewall->Firewall Configuration->All Outgoing TCP Ports, add 3306. Good night.
https://snipt.net/embed/0cd265948407cb5555c40af9a2f15e5f/
https://snipt.net/raw/0cd265948407cb5555c40af9a2f15e5f/
0cd265948407cb5555c40af9a2f15e5f
text
Text only
8
2016-09-25T06:54:16
True
False
False
Dec 31, 2014 at 12:57 PM
/api/public/snipt/137743/
allow-remote-db-connections-on-port-3306-for-whm-ba238b79
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>Answer From http://forums.cpanel.net/f354/whm-server-not-allowing-remote-db-connection-408421.html </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>WHM Server Not Allowing Remote DB Connection </span><span id="L-4"><a name="L-4"></a>I&#39;m having trouble figuring out why our web server won&#39;t connect to Amazon RDS. I&#39;ve connected via command line on a simple CentOS server and from several computers via MySQL Workbench. The RDS security groups are set up properly. The command I&#39;m using should otherwise work. Is it possible my server is blocking outgoing connections to port 3306 and where would I change this? </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a>- - - Updated - - - </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a>Never mind. I should have known it would be in CSF. For anyone else who is up late at night after working all day and have a tired brain, WHM-&gt;ConfigServer Firewall-&gt;Firewall Configuration-&gt;All Outgoing TCP Ports, add 3306. Good night. </span></pre></div> </td></tr></table>
"port 3306", "remote database", "remote db", 3306, cpanel, database, whm

Bash

psql > list databases

$ psql -l
https://snipt.net/embed/235856f12c616a3577752c1c5d7d09bc/
https://snipt.net/raw/235856f12c616a3577752c1c5d7d09bc/
235856f12c616a3577752c1c5d7d09bc
bash
Bash
1
2016-09-25T02:40:57
True
False
False
/api/public/snipt/136197/
psql-list-databases-8ad5d699
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nv">$ </span>psql -l </span></pre></div> </td></tr></table>
database, postgres, postgresql, psql

Ruby

Rails migration in console

ActiveRecord::Migration.drop_table(:users)
https://snipt.net/embed/7c622ac35646103e349ee5de11a5224c/
https://snipt.net/raw/7c622ac35646103e349ee5de11a5224c/
7c622ac35646103e349ee5de11a5224c
rb
Ruby
1
2016-09-25T02:41:03
True
False
False
/api/public/snipt/135183/
rails-migration-in-console-94b98189
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span><span class="o">.</span><span class="n">drop_table</span><span class="p">(</span><span class="ss">:users</span><span class="p">)</span> </span></pre></div> </td></tr></table>
database, migration, rails, ruby

SQL

Delete Property from Umbraco Doc Type via SQL DB

1
2
3
4
5
6
7
8
DECLARE @id int
SET @id = 69 /* id of the propertytype that you can't delete in the Umbraco backend*/

DELETE FROM [dbo].[cmsPropertyData]
 WHERE [propertytypeid] = @id
  
DELETE FROM [dbo].[cmsPropertyType]
 WHERE [id] = @id
https://snipt.net/embed/8d2ed8e8ef9f431682a55714d7a2946b/
https://snipt.net/raw/8d2ed8e8ef9f431682a55714d7a2946b/
8d2ed8e8ef9f431682a55714d7a2946b
sql
SQL
8
2016-09-25T02:56:45
True
False
False
Mar 02, 2014 at 08:16 PM
/api/public/snipt/118164/
delete-property-from-umbraco-doc-type-via-sql-db
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">DECLARE</span> <span class="o">@</span><span class="n">id</span> <span class="nb">int</span> </span><span id="L-2"><a name="L-2"></a><span class="k">SET</span> <span class="o">@</span><span class="n">id</span> <span class="o">=</span> <span class="mi">69</span> <span class="cm">/* id of the propertytype that you can&#39;t delete in the Umbraco backend*/</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="k">DELETE</span> <span class="k">FROM</span> <span class="p">[</span><span class="n">dbo</span><span class="p">].[</span><span class="n">cmsPropertyData</span><span class="p">]</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">WHERE</span> <span class="p">[</span><span class="n">propertytypeid</span><span class="p">]</span> <span class="o">=</span> <span class="o">@</span><span class="n">id</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="k">DELETE</span> <span class="k">FROM</span> <span class="p">[</span><span class="n">dbo</span><span class="p">].[</span><span class="n">cmsPropertyType</span><span class="p">]</span> </span><span id="L-8"><a name="L-8"></a> <span class="k">WHERE</span> <span class="p">[</span><span class="n">id</span><span class="p">]</span> <span class="o">=</span> <span class="o">@</span><span class="n">id</span> </span></pre></div> </td></tr></table>
database, sql, umbraco

Ruby

activerecord > current database and tables

> ActiveRecord::Base.connection.current_database
> ActiveRecord::Base.connection.tables
https://snipt.net/embed/262b148fa0ff82559a980bb10c659a4e/
https://snipt.net/raw/262b148fa0ff82559a980bb10c659a4e/
262b148fa0ff82559a980bb10c659a4e
rb
Ruby
2
2016-09-25T02:41:14
True
False
False
/api/public/snipt/117401/
activerecord-current-database
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="o">&gt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">current_database</span> </span><span id="L-2"><a name="L-2"></a><span class="o">&gt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">tables</span> </span></pre></div> </td></tr></table>
console, database, rails, ruby

Shell Session

Import sql file to MySQL database using SSH

mysql -p -u DB_USERNAME DB_NAME < PATH/TO/FILE.sql
https://snipt.net/embed/2889d808e26a0fbea9ed3b8e1bfeeecf/
https://snipt.net/raw/2889d808e26a0fbea9ed3b8e1bfeeecf/
2889d808e26a0fbea9ed3b8e1bfeeecf
shell-session
Shell Session
1
2016-09-25T01:12:35
True
False
False
Feb 17, 2014 at 05:03 PM
/api/public/snipt/114552/
import-sql-file-to-mysql-database-using-ssh
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="go">mysql -p -u DB_USERNAME DB_NAME &lt; PATH/TO/FILE.sql</span> </span></pre></div> </td></tr></table>
database, mysql, sql, ssh, terminal
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.