A 38-year-old's MYSQL primer~
The home server I'm running on a LattePanda has been acting up lately. Seems like it'll take a while to get through just the fix-ups, so I figured I'd take this as a chance to start learning MYSQL.
My reference book is 'SQL First Steps.' The examples are in MYSQL, so I had only read it once without practicing — now I want to actually walk through the examples. As the book itself notes, Oracle, MYSQL, and MariaDB differ a bit, but not drastically, so even when I later work in Oracle I don't expect serious issues.
So before diving in, let me tune the blog a little.
0. Applying a plugin so I can embed development code on the blog
- Before writing the MYSQL primer, let me fix the blog so it can display dev code nicely.
- When writing a post:
1) In the top-right of the blog editor, if you tick the ㅁ HTML checkbox, the entire editor content switches to HTML tag format.
2) At the desired position, insert <pre class="line-numbers" style="margin:3%"><code class="language-sql"> write the code you want here </code></pre>. When you're done entering code, untick the ㅁ HTML checkbox again and the editor goes back to the text-based view. ~
- Reference blog: Applying Prism to Tistory https://melony1024.tistory.com/6 (2017.08.02)
1. MYSQL install and connection setup
1-0) My machine / dev environment: Mac OS, working in terminal
1-1) Installation is surprisingly simple. Compared to Oracle it's dead simple. Just this one line.
brew install mysql
> Of course I hit an error on this simple step. -_- Permissions, apparently.
> But MySQL was friendlier than I expected. It said "You should change the ownership..." and even showed me the exact command to run!
> So I took the line below with "sudo chown -R..." and pasted it verbatim. (like the blue line below )
> It asks for your computer's password. Of course, nothing shows up as you type on the keyboard.
> Just type it all out and press Enter — it simply moves to a new line as if nothing happened.
> If it moves to the next line with no error message, the permission ( ownership ) change was applied.
> Alright, now run brew install mysql again. Nine times out of ten, it works.
1-2) OK, now let's start MYSQL.
mysql.server start 1-3) Let's configure the MYSQL server connection.
mysql_secure_installation
> Would you like to setup VALIDATE PASSWORD plugin? : whether to use MySQL's built-in password policy
> (A): if you answered N above you can skip this step
> Please enter 0,1,2 : (I kinda regretted pressing y at first... so here I went with 0, the shortest option, and entered an 8-character password)
> Remove anonymous users? : whether to remove the anonymous user (if yes, you must always specify -u when connecting)
> Disallow root login remotely? : whether to allow root login from IPs other than localhost (if you say yes, remote access is blocked, so I said no)
> Remove test database and access to it? : whether to remove MySQL's default test DB (I said yes)
> Reload privilege tables now? : whether to reload privilege changes
3. OK, now let's connect to mysql for real.
mysql -u root -p
> On a successful connection it prints something like this.
- Reference blogs: Installing MySQL on Mac https://zzsza.github.io/development/2018/01/18/Install-MySQL-mac/ (2018.01.18)
Installing MySQL simply (Mac, HomeBrew) https://junhobaik.github.io/mac-install-mysql/ (2018.01.29)
