Add basic DB guide articles
parent
df4d70a598
commit
ec8c40f001
@ -0,0 +1,85 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="description" content="">
|
||||||
|
<meta name="keywords" content="Blog, articles, guide, mysql, mariadb, database">
|
||||||
|
<meta name="author" content="Nathan (Aney) Steel">
|
||||||
|
<meta name="theme-color" content="white">
|
||||||
|
<meta name="theme-color" content="black">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/main.css">
|
||||||
|
<link rel="icon" type="image/png" href="/images/favicon.svg">
|
||||||
|
<title>Adminer Setup</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>Adminer Setup</h1>
|
||||||
|
<hr/>
|
||||||
|
<nav>
|
||||||
|
<a href="/">home</a>
|
||||||
|
<a href="/equipment.html">equipment</a>
|
||||||
|
<a href="/projects.html">projects</a>
|
||||||
|
<a href="/blog/">blog</a>
|
||||||
|
<a href="/sitemap.html">misc</a>
|
||||||
|
<a href="/support.html">support</a>
|
||||||
|
</nav>
|
||||||
|
<hr/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<p>Adminer is a simple front-end for your database server that can be access through the browser</p>
|
||||||
|
<h2>Pre-Requirements</h2>
|
||||||
|
<p>To run adminer, you'll need a webserver with php set up. Thankfully I'm a great guy, and have written about these topics before.</p>
|
||||||
|
<ul>
|
||||||
|
<li><a href="/blog/nginx-install.html">Nginx Webserver Setup</a></li>
|
||||||
|
<li>PHP setup for NGINX</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Download the latest release</h2>
|
||||||
|
<p>This will download the latest release to your default web directory, this can be changed, by altering the path following <strong>-O</strong>.</p>
|
||||||
|
<pre><code>wget "http://www.adminer.org/latest.php" -O /var/www/html/adminer.php</code></pre>
|
||||||
|
|
||||||
|
<h2>Set permissions for your web server</h2>
|
||||||
|
<pre><code>chown -R www-data:www-data /var/www/html/adminer.php
|
||||||
|
chmod 755 /var/www/html/adminer.php</code></pre>
|
||||||
|
|
||||||
|
<h2>Access it</h2>
|
||||||
|
<p>Head to your <WEBSITE/IP>/adminer.php, and you should load into the adminer login. Using your mysql/mariaDB credentials, you can then login, and use the GUI to manage your database(s)</p>
|
||||||
|
|
||||||
|
<h2>Make it a directory, not a file</h2>
|
||||||
|
<p>Instead of accessing /adminer.php?<ARGUMENTS>, we can make it look like /adminer/<ARGUMENTS></p>
|
||||||
|
<pre><code>location /adminer/ {
|
||||||
|
root /var/www/html ;
|
||||||
|
try_files $uri $uri/ /adminer/index.php/$is_args$args ;
|
||||||
|
}</code></pre>
|
||||||
|
|
||||||
|
<h2>Password Protect</h2>
|
||||||
|
<p>An additional level of security, just in case. Using Htaccess, any file, or directory can be password protected</p>
|
||||||
|
<pre><code>sudo apt install apache2-utils
|
||||||
|
htpasswd -c /home/<USER>/.htpasswd admin</code></pre>
|
||||||
|
|
||||||
|
<h3>Add to location</h3>
|
||||||
|
<p>Add the location of the auth file to the adminer location block</p>
|
||||||
|
<pre><code>auth_basic "Adminer" ;
|
||||||
|
auth_basic_user_file /home/<USER>/.htpasswd ;</code></pre>
|
||||||
|
<p>They block should look like below</p>
|
||||||
|
<pre><code>location /adminer/ {
|
||||||
|
auth_basic "Adminer" ;
|
||||||
|
auth_basic_user_file /home/<USER>/.htpasswd ;
|
||||||
|
root /var/www/html ;
|
||||||
|
try_files $uri $uri/ /adminer/index.php/$is_args$args ;
|
||||||
|
}</code></pre>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<hr/>
|
||||||
|
<p>Written by <a href="http://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="description" content="">
|
||||||
|
<meta name="keywords" content="Blog, articles, guide, mysql, mariadb, database">
|
||||||
|
<meta name="author" content="Nathan (Aney) Steel">
|
||||||
|
<meta name="theme-color" content="white">
|
||||||
|
<meta name="theme-color" content="black">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/main.css">
|
||||||
|
<link rel="icon" type="image/png" href="/images/favicon.svg">
|
||||||
|
<title>Backup MySQL/MariaDB</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>Backup MySQL/MariaDB</h1>
|
||||||
|
<hr/>
|
||||||
|
<nav>
|
||||||
|
<a href="/">home</a>
|
||||||
|
<a href="/equipment.html">equipment</a>
|
||||||
|
<a href="/projects.html">projects</a>
|
||||||
|
<a href="/blog/">blog</a>
|
||||||
|
<a href="/sitemap.html">misc</a>
|
||||||
|
<a href="/support.html">support</a>
|
||||||
|
</nav>
|
||||||
|
<hr/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<p>A database if a huge part of many projects, services, and servers. If something goes wrong, data is wrongly updated/deleted there could be many problems. Thankfully we can make backups to make sure our data is safe.</p>
|
||||||
|
<h2>Manual Backup of a DB</h2>
|
||||||
|
|
||||||
|
<h2>Backup all DBs</h2>
|
||||||
|
<p>This follows on from the manual backup, so assumes you have the backup directory created</p>
|
||||||
|
<h2>Automate hourly backups</h2>
|
||||||
|
|
||||||
|
<h2>My backup script</h2>
|
||||||
|
<p>I follow the 3-2-1 backup approach, so I want to keep the files in multiple locations</p>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<hr/>
|
||||||
|
<p>Written by <a href="http://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="description" content="">
|
||||||
|
<meta name="keywords" content="Blog, articles, guide, mysql, mariadb, database">
|
||||||
|
<meta name="author" content="Nathan (Aney) Steel">
|
||||||
|
<meta name="theme-color" content="white">
|
||||||
|
<meta name="theme-color" content="black">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/main.css">
|
||||||
|
<link rel="icon" type="image/png" href="/images/favicon.svg">
|
||||||
|
<title>MySQL (actually MariaDB) Setup Guide</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>MySQL (actually MariaDB) Setup Guide</h1>
|
||||||
|
<hr/>
|
||||||
|
<nav>
|
||||||
|
<a href="/">home</a>
|
||||||
|
<a href="/equipment.html">equipment</a>
|
||||||
|
<a href="/projects.html">projects</a>
|
||||||
|
<a href="/blog/">blog</a>
|
||||||
|
<a href="/sitemap.html">misc</a>
|
||||||
|
<a href="/support.html">support</a>
|
||||||
|
</nav>
|
||||||
|
<hr/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<p>MySQL is a well known free, open-source relational database service, and it's great. MariaDB is just MySQL (a fork of it), but better.</p>
|
||||||
|
|
||||||
|
<h2>Install MariaDB</h2>
|
||||||
|
<pre><code>sudo apt install mariadb-server</code></pre>
|
||||||
|
|
||||||
|
<h2>Secure Install/Setup</h2>
|
||||||
|
<pre><code>sudo mysql_secure_installation</code></pre>
|
||||||
|
|
||||||
|
<h2>Create Admin user</h2>
|
||||||
|
<pre><code>sudo mysql</code></pre>
|
||||||
|
|
||||||
|
<pre><code>GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;</code></pre>
|
||||||
|
<pre><code>FLUSH PRIVILEGES;</code></pre>
|
||||||
|
<pre><code>exit;</code></pre>
|
||||||
|
|
||||||
|
<h2>Test it works</h2>
|
||||||
|
|
||||||
|
<h2>(Optional) Make it easier to access on command line</h2>
|
||||||
|
<p>If you're working with a terminal, when calling <code>mysql</code> you'll need to enter a password each time. You can store the passwordwith a special .cnf file, making it faster to get into writing SQL.</p>
|
||||||
|
<p>Create/Edit the file with your editor of choice (mine's vim)</p>
|
||||||
|
<pre><code>vim ~/.my.cnf</code></pre>
|
||||||
|
<p>Add the following, with your credentials</p>
|
||||||
|
<pre><code>[mysql]
|
||||||
|
user=<USERNAME>
|
||||||
|
password=<PASSWORD></code></pre>
|
||||||
|
<p>The above can be used for mysqldump, mysqladmin, and others too, by replacing the <code>[mysql]</code> block</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<hr/>
|
||||||
|
<p>Written by <a href="http://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="description" content="Basic SQL cheatsheet for the commandline.">
|
||||||
|
<meta name="keywords" content="Blog, articles, guide, mysql, mariadb, database">
|
||||||
|
<meta name="author" content="Nathan (Aney) Steel">
|
||||||
|
<meta name="theme-color" content="white">
|
||||||
|
<meta name="theme-color" content="black">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/main.css">
|
||||||
|
<link rel="icon" type="image/png" href="/images/favicon.svg">
|
||||||
|
<title>SQL Cheatsheet</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>SQL Cheatsheet</h1>
|
||||||
|
<hr/>
|
||||||
|
<nav>
|
||||||
|
<a href="/">home</a>
|
||||||
|
<a href="/equipment.html">equipment</a>
|
||||||
|
<a href="/projects.html">projects</a>
|
||||||
|
<a href="/blog/">blog</a>
|
||||||
|
<a href="/sitemap.html">misc</a>
|
||||||
|
<a href="/support.html">support</a>
|
||||||
|
</nav>
|
||||||
|
<hr/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<p>SQL is a great, simple to use language to manipulate data within a database. This cheatsheet is aimed at basic SQL for MySQL/MariaDB.</p>
|
||||||
|
|
||||||
|
<h2>Access on the command line</h2>
|
||||||
|
<pre><code>mysql -u <USERNAME> -p</code></pre>
|
||||||
|
<p>When prompted enter your password</p>
|
||||||
|
|
||||||
|
<h2>Database manipulation</h2>
|
||||||
|
<h3>Show databases</h3>
|
||||||
|
<pre><code>SHOW databases;</code></pre>
|
||||||
|
|
||||||
|
<h3>Create new databases</h3>
|
||||||
|
<pre><code>CREATE DATABASE IF NOT EXISTS <DATABASE>;</code></pre>
|
||||||
|
|
||||||
|
<h3>Enter into a database</h3>
|
||||||
|
<pre><code>USE DATABASE <DATABASE>;</code></pre>
|
||||||
|
<p>or just</p>
|
||||||
|
<pre><code>USE <DATABASE>;</code></pre>
|
||||||
|
|
||||||
|
<h2>Table manipulation</h2>
|
||||||
|
<p>Once you've got a database selected, you can play with tables</p>
|
||||||
|
<h3>Create</h3>
|
||||||
|
<h3>Read</h3>
|
||||||
|
<h3>Update</h3>
|
||||||
|
<h3>Delete</h3>
|
||||||
|
|
||||||
|
<h2>Data manipulation</h2>
|
||||||
|
<p>Most of your SQL life will be CRUDing (Create, Read, Update, Delete) data. So I'll cover the basics here</p>
|
||||||
|
<h3>Create</h3>
|
||||||
|
<h3>Read</h3>
|
||||||
|
<h3>Update</h3>
|
||||||
|
<h3>Delete</h3>
|
||||||
|
|
||||||
|
<h2>Create additional users</h2>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<hr/>
|
||||||
|
<p>Written by <a href="http://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
Loading…
Reference in New Issue