snipt

Ctrl+h for KB shortcuts

MySQL

cakephp initial posts table

1
2
3
4
5
6
7
8
CREATE TABLE posts (
    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    user_id INT(11) NOT NULL,
    title VARCHAR(255) NOT NULL,
    body TEXT,
    created DATETIME,
    modified DATETIME
);
https://snipt.net/embed/8dff735da5c8b06432139817b2526905/
/raw/8dff735da5c8b06432139817b2526905/
8dff735da5c8b06432139817b2526905
mysql
MySQL
8
2019-05-23T21:56:14
True
False
False
/api/public/snipt/4856/
cakephp-initial-posts-table
<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></span><span id="L-1"><a name="L-1"></a><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="nf">posts</span> <span class="p">(</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">id</span> <span class="kt">INT</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span> <span class="k">NOT</span> <span class="no">NULL</span> <span class="kp">AUTO_INCREMENT</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">user_id</span> <span class="kt">INT</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span> <span class="k">NOT</span> <span class="no">NULL</span><span class="p">,</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">title</span> <span class="kt">VARCHAR</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span> <span class="k">NOT</span> <span class="no">NULL</span><span class="p">,</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">body</span> <span class="kt">TEXT</span><span class="p">,</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">created</span> <span class="kt">DATETIME</span><span class="p">,</span> </span><span id="L-7"><a name="L-7"></a> <span class="n">modified</span> <span class="kt">DATETIME</span> </span><span id="L-8"><a name="L-8"></a><span class="p">);</span> </span></pre></div> </td></tr></table>
cakephp, mysql

MySQL

cake php initial user table

1
2
3
4
5
6
7
CREATE TABLE users (
    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(255) NOT NULL UNIQUE,
    password CHAR(40) NOT NULL,
    created DATETIME,
    modified DATETIME
);
https://snipt.net/embed/0031b7849ca9765b9fe02bf534343efc/
/raw/0031b7849ca9765b9fe02bf534343efc/
0031b7849ca9765b9fe02bf534343efc
mysql
MySQL
7
2019-05-24T21:20:56
True
False
False
/api/public/snipt/4855/
cake-php-initial-user-table
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="nf">users</span> <span class="p">(</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">id</span> <span class="kt">INT</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span> <span class="k">NOT</span> <span class="no">NULL</span> <span class="kp">AUTO_INCREMENT</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">username</span> <span class="kt">VARCHAR</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span> <span class="k">NOT</span> <span class="no">NULL</span> <span class="k">UNIQUE</span><span class="p">,</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">password</span> <span class="kt">CHAR</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span> <span class="k">NOT</span> <span class="no">NULL</span><span class="p">,</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">created</span> <span class="kt">DATETIME</span><span class="p">,</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">modified</span> <span class="kt">DATETIME</span> </span><span id="L-7"><a name="L-7"></a><span class="p">);</span> </span></pre></div> </td></tr></table>
cakephp, mysql

Bash

backup all dbs in mysql and gzip

15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`data ' %m-%d-%Y'`.sql.gz
https://snipt.net/embed/e92a524b5203ef9e5a3836080b261075/
/raw/e92a524b5203ef9e5a3836080b261075/
e92a524b5203ef9e5a3836080b261075
bash
Bash
1
2019-06-15T08:45:33
True
False
False
/api/public/snipt/4051/
backup-all-dbs-in-mysql-and-gzip
<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></span><span id="L-1"><a name="L-1"></a><span class="m">15</span> <span class="m">2</span> * * * root mysqldump -u root -pPASSWORD --all-databases <span class="p">|</span> gzip &gt; /mnt/disk2/database_<span class="sb">`</span>data <span class="s1">&#39; %m-%d-%Y&#39;</span><span class="sb">`</span>.sql.gz </span></pre></div> </td></tr></table>
mysql

MySQL

insert new domain into mail db on slicehost

INSERT INTO `domains` (`domain`) VALUES ('demoslice.com');
https://snipt.net/embed/0f0109e582cc198f16f3ee90a9914761/
/raw/0f0109e582cc198f16f3ee90a9914761/
0f0109e582cc198f16f3ee90a9914761
mysql
MySQL
1
2019-05-24T13:14:49
True
False
False
/api/public/snipt/3515/
insert-new-domain-into-mail-db-on-slicehost
<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></span><span id="L-1"><a name="L-1"></a><span class="k">INSERT</span> <span class="k">INTO</span> <span class="ss">`domains`</span> <span class="p">(</span><span class="ss">`domain`</span><span class="p">)</span> <span class="k">VALUES</span> <span class="p">(</span><span class="s1">&#39;demoslice.com&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
email, mysql

MySQL

dump mysql database to file

mysqldump --user=root --password=root --host localhost dbname > filename.sql
https://snipt.net/embed/9cbfa0df9af400b7e9a4318973eb1bf3/
/raw/9cbfa0df9af400b7e9a4318973eb1bf3/
9cbfa0df9af400b7e9a4318973eb1bf3
mysql
MySQL
1
2019-05-24T17:31:49
True
False
False
/api/public/snipt/2564/
dump-mysql-database-to-file
<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></span><span id="L-1"><a name="L-1"></a><span class="n">mysqldump</span> <span class="o">--</span><span class="n">user</span><span class="o">=</span><span class="n">root</span> <span class="o">--</span><span class="n">password</span><span class="o">=</span><span class="n">root</span> <span class="o">--</span><span class="n">host</span> <span class="n">localhost</span> <span class="n">dbname</span> <span class="o">&gt;</span> <span class="n">filename</span><span class="p">.</span><span class="k">sql</span> </span></pre></div> </td></tr></table>
mysql

MySQL

update mysql table data with string replace

update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
https://snipt.net/embed/784ae575d8f6fba27fec20c75428e28d/
/raw/784ae575d8f6fba27fec20c75428e28d/
784ae575d8f6fba27fec20c75428e28d
mysql
MySQL
1
2019-06-03T04:30:37
True
False
False
/api/public/snipt/2233/
update-mysql-table-data-with-string-replace
<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></span><span id="L-1"><a name="L-1"></a><span class="k">update</span> <span class="p">[</span><span class="n">table_name</span><span class="p">]</span> <span class="kt">set</span> <span class="p">[</span><span class="n">field_name</span><span class="p">]</span> <span class="o">=</span> <span class="k">replace</span><span class="p">([</span><span class="n">field_name</span><span class="p">],</span><span class="s1">&#39;[string_to_find]&#39;</span><span class="p">,</span><span class="s1">&#39;[string_to_replace]&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
mysql

MySQL

insert user into mail db

INSERT INTO `users` (`email`, `password`) VALUES ('[email protected]', ENCRYPT('secretpassword'));
https://snipt.net/embed/dd9511a6ed734fa7bb38ae59c8229e7f/
/raw/dd9511a6ed734fa7bb38ae59c8229e7f/
dd9511a6ed734fa7bb38ae59c8229e7f
mysql
MySQL
1
2019-06-04T01:22:40
True
False
False
/api/public/snipt/2071/
insert-user-into-mail-db
<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></span><span id="L-1"><a name="L-1"></a><span class="k">INSERT</span> <span class="k">INTO</span> <span class="ss">`users`</span> <span class="p">(</span><span class="ss">`email`</span><span class="p">,</span> <span class="ss">`password`</span><span class="p">)</span> <span class="k">VALUES</span> <span class="p">(</span><span class="s1">&#39;[email protected]&#39;</span><span class="p">,</span> <span class="nf">ENCRYPT</span><span class="p">(</span><span class="s1">&#39;secretpassword&#39;</span><span class="p">));</span> </span></pre></div> </td></tr></table>
email, mysql

Bash

import mysql dump to db

mysql -uusername -ppassword -hlocalhost sourcedb < targetdbdump.sql
https://snipt.net/embed/8d1925908aaef284b7f06ff66111e67e/
/raw/8d1925908aaef284b7f06ff66111e67e/
8d1925908aaef284b7f06ff66111e67e
bash
Bash
1
2019-05-25T00:28:23
True
False
False
/api/public/snipt/971/
import-mysql-dump-to-db
<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></span><span id="L-1"><a name="L-1"></a>mysql -uusername -ppassword -hlocalhost sourcedb &lt; targetdbdump.sql </span></pre></div> </td></tr></table>
mysql

MySQL

update mysql table data

UPDATE snippet_snippet SET public=0;
https://snipt.net/embed/5b6fcb789a01a5c7e79c5a4120258496/
/raw/5b6fcb789a01a5c7e79c5a4120258496/
5b6fcb789a01a5c7e79c5a4120258496
mysql
MySQL
1
2019-06-04T02:23:47
True
False
False
/api/public/snipt/321/
update-mysql-table-data
<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></span><span id="L-1"><a name="L-1"></a><span class="k">UPDATE</span> <span class="n">snippet_snippet</span> <span class="kt">SET</span> <span class="n">public</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> </span></pre></div> </td></tr></table>
mysql