<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.rosemarknetworks.com/wiki/index.php?action=history&amp;feed=atom&amp;title=MySQL</id>
	<title>MySQL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.rosemarknetworks.com/wiki/index.php?action=history&amp;feed=atom&amp;title=MySQL"/>
	<link rel="alternate" type="text/html" href="https://www.rosemarknetworks.com/wiki/index.php?title=MySQL&amp;action=history"/>
	<updated>2026-06-16T05:48:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://www.rosemarknetworks.com/wiki/index.php?title=MySQL&amp;diff=11&amp;oldid=prev</id>
		<title>Rosemark: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://www.rosemarknetworks.com/wiki/index.php?title=MySQL&amp;diff=11&amp;oldid=prev"/>
		<updated>2024-10-07T18:55:05Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:55, 7 October 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Rosemark</name></author>
	</entry>
	<entry>
		<id>https://www.rosemarknetworks.com/wiki/index.php?title=MySQL&amp;diff=10&amp;oldid=prev</id>
		<title>wikipedia&gt;Maeve at 21:20, 12 June 2023</title>
		<link rel="alternate" type="text/html" href="https://www.rosemarknetworks.com/wiki/index.php?title=MySQL&amp;diff=10&amp;oldid=prev"/>
		<updated>2023-06-12T21:20:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Overview= &lt;br /&gt;
&amp;lt;b&amp;gt;MySQL&amp;lt;/b&amp;gt; is an [[RDBMS]] database standard most commonly implemented as MySQL Server or its modern, cross-compatible counterpart, MariaDB. Due to its more modern nature, this guide assumes at all points that the DB in question is MariaDB. There&amp;#039;s no meaningful difference for the sake of this documentation unless explicitly stated. MySQL is one of the most popular database backends in the industry, and is the database of preference for [[MediaWiki]] and [[Zabbix|both Zabbix Server and Proxy]]. &lt;br /&gt;
MySQL uses its own dialect of [[SQL]]. MariaDB exactly matches MySQL&amp;#039;s API calls and SQL variety, though newer features diverge from traditional MySQL. &amp;lt;sup&amp;gt;(investigate this!)&amp;lt;/sup&amp;gt;  &lt;br /&gt;
=Installation and Initial Database Creation Steps=&lt;br /&gt;
See [[Unix Package Managers]] for non-APT repositories. Assumes Debian / Ubuntu. &amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt;apt update&amp;lt;/b&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt;apt install mariadb-server&amp;lt;/b&amp;gt;&lt;br /&gt;
The default MySQL database has nothing in it, and one user, &amp;#039;root&amp;#039;@&amp;#039;localhost&amp;#039;. Users are defined by host. &amp;lt;br&amp;gt;  &lt;br /&gt;
Due to its compatibility with standard MySQL, you can use the MySQL command as well as third party applications that refer to MySQL. &amp;lt;br&amp;gt;  &lt;br /&gt;
To enter the MySQL console: &amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt;(sudo) mysql -uroot -p&amp;lt;/b&amp;gt; &lt;br /&gt;
* -u is a prefix following the name of the user. You can have a space between it and the username, but it seems convention is to leave it out. &lt;br /&gt;
* The above stipulation applies to all options except -p, which signifies the password. The password MUST immediately follow it. If the password is left blank, the stdin will poll you for it, then follow after authentication. &lt;br /&gt;
* The default password seems to be the password of the account that installs and starts MySQL. &lt;br /&gt;
Let&amp;#039;s create a simple database, give it a table, give it two entries, and then move on. &amp;lt;br&amp;gt;&lt;br /&gt;
From the console, type: &amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt; CREATE DATABASE testDatabase;&amp;lt;/b&amp;gt;&lt;br /&gt;
This creates the database.&lt;br /&gt;
: &amp;lt;b&amp;gt; USE testDatabase;&amp;lt;/b&amp;gt; &lt;br /&gt;
This sets testDatabase as the currently active database - one MySQL installation can house &amp;lt;b&amp;gt;multiple&amp;lt;/b&amp;gt; databases.&lt;br /&gt;
: &amp;lt;b&amp;gt; CREATE TABLE thisIsATestTable (testColumn1_ID int, testColumn2_Name varchar(255));&amp;lt;/b&amp;gt;&lt;br /&gt;
This creates a table in testDatabase with two columns, one integer and one 255 character string. &lt;br /&gt;
Let&amp;#039;s add two entries:  &lt;br /&gt;
: &amp;lt;b&amp;gt; INSERT INTO thisIsATestTable VALUES (1, &amp;#039;Hello&amp;#039;);&amp;lt;/b&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt; INSERT INTO thisIsATestTable VALUES (2, &amp;#039;World&amp;#039;);&amp;lt;/b&amp;gt;&lt;br /&gt;
We use the &amp;lt;b&amp;gt;INSERT INTO&amp;lt;/b&amp;gt; keyword to select the table we&amp;#039;re adding the entries to, and then VALUES acts sort of like a function taking a set of values as parameters to insert, following the schema of the table. If you wish to only insert into one column (or any partial collection of the table&amp;#039;s columns) you may use the following format: &lt;br /&gt;
: &amp;lt;b&amp;gt; INSERT INTO thisIsATestTable(testColumn2_name) VALUES (&amp;#039;from the otherside&amp;#039;);&amp;lt;/b&amp;gt; &lt;br /&gt;
In this situation, the columns we don&amp;#039;t add values to will be null. Case in point: &amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt; SELECT * FROM thisIsATestTable; &amp;lt;/b&amp;gt;&lt;br /&gt;
:: &amp;lt;i&amp;gt;1 - Hello&amp;lt;/i&amp;gt;&lt;br /&gt;
:: &amp;lt;i&amp;gt;1 - World&amp;lt;/i&amp;gt;&lt;br /&gt;
:: &amp;lt;i&amp;gt;null - from the otherside&amp;lt;/i&amp;gt;&lt;br /&gt;
We could, of course, set this up to auto increment by entry, by defining our table as such: &amp;lt;br&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt; CREATE TABLE thisIsATestTable (testColumn1_ID int NOT NULL AUTO_INCREMENT, testColumn2_Name varchar(255), PRIMARY KEY(testColumn1_ID));&amp;lt;/b&amp;gt;  &lt;br /&gt;
After doing this, we use null instead of a number when adding a whole entry, or if partial, we specify all columns except the ID. Once it enters into the database, it will get an ID by order of insertion.&lt;br /&gt;
=Backups using automysqlbackup=&lt;br /&gt;
We can backup our MySQL databases through automysqlbackup, a third party package we can download that converts our databases into sql files that first create the database, table, etc, then populate their values. The next subsection covers the restoration process.  &lt;br /&gt;
First, install automysqlbackup:&lt;br /&gt;
: &amp;lt;b&amp;gt;apt update&amp;lt;/b&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt;apt install automysqlbackup&amp;lt;/b&amp;gt;&lt;br /&gt;
We can then run it just by itself:  &lt;br /&gt;
: &amp;lt;b&amp;gt;automysqlbackup&amp;lt;/b&amp;gt; &lt;br /&gt;
The results appear in /var/lib/automysqlbackup/ with the first backup done appearing in the /var/lib/automysqlbackup/daily directory. Each individual database appears as its own directory, and in these directories are SQL script files, packaged as [[Gunzip|gzips]].    &lt;br /&gt;
=Formatting databases through piping=&lt;br /&gt;
We can use SQL script files to restore a backup. Since the SQL scripts are just SQL that reconstructs the database from scratch, we can use the MySQL command and pipe these scripts into it. This method assumes the database itself is already created, but empty. This can be preceded just by using &amp;lt;b&amp;gt;CREATE DATABASE &amp;lt;i&amp;gt;name&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;. The formula for this is essentially using gunzip to unzip the file and piping them in: &lt;br /&gt;
: &amp;lt;b&amp;gt;gunzip -c file.sql.gz | mysql -uroot -p&amp;lt;/b&amp;gt;&lt;br /&gt;
=Users and remote access=&lt;br /&gt;
Last major note here, access to a given database and tables within it are assumed blocked for all users by default and need to be specified. Further, users are differentiated by both name and host, so that for example, a non-root user on the localhost might have higher permissions than the same non-root user communicating from an on-site workstation, and higher still than the same non-root user communicating offsite. Here&amp;#039;s an example: &lt;br /&gt;
: &amp;lt;b&amp;gt;CREATE USER &amp;#039;maeve&amp;#039;@&amp;#039;localhost&amp;#039; IDENTIFIED BY &amp;#039;password&amp;#039; WITH GRANT OPTION;&amp;lt;/b&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt;GRANT ALL PRIVILEGES ON testDatabase.* TO &amp;#039;Maeve&amp;#039;@&amp;#039;localhost&amp;#039;;&amp;lt;/b&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt;CREATE USER &amp;#039;maeve&amp;#039;@&amp;#039;192.168.4.25&amp;#039; IDENTIFIED BY &amp;#039;password&amp;#039;;&amp;lt;/b&amp;gt;&lt;br /&gt;
: &amp;lt;b&amp;gt;GRANT ALL PRIVILEGES ON testDatabase.thisIsATestTable TO &amp;#039;Maeve&amp;#039;@&amp;#039;192.168.4.25&amp;#039;;&amp;lt;/b&amp;gt;&lt;br /&gt;
This is mostly self explanatory but I will mention that WITH GRANT OPTION specifies that, logged in as &amp;#039;maeve&amp;#039;@&amp;#039;localhost&amp;#039;, the user could grant the same permissions to another user, essentially allowing for delegation.&lt;br /&gt;
==Notes==&lt;br /&gt;
* In MySQL, double quotes aren&amp;#039;t used for string delimination. We use single quotes instead, and two single quotes together for a single quote within a string, such as a possessive apostrophe. &lt;br /&gt;
[[Category:Infrastructure]]&lt;/div&gt;</summary>
		<author><name>wikipedia&gt;Maeve</name></author>
	</entry>
</feed>