How to install MySQL

MySQL installation locally

Check if Homebrew is installed

brew --version

With the Homebrew installation completed, then install MySQL. If you want to specify the version, specify it.

brew install mysql

Check the installed MySQL information with the following command

brew info mysql

When creating a new application with Rails, SQLite is set by default, so it is explicitly declared to use MySQL as follows in the command when creating a new application.

rails new application name-d mysql

The following command to "start" MySQL

mysql.server start

Since you need to log in to actually use MySQL, log in as the "root" user that is prepared by default. You can log in as the "root" user with the following command.

mysql -uroot

MySQL uses a lot of memory, so it is recommended to stop the database when it is not in use. Command to stop MySQL ↓

mysql.server stop

MySQL security settings

mysql_secure_installation

Reference ↓ Let's install MySQL on Mac environment! Thorough explanation of the procedure up to the initial setting! | "Potepan Style"

Server startup

After setting, start the server

mysql.server start
rails s

Login with the registered password

mysql -uroot -p

http://localhost:3000/ Opens but fails ↓ スクリーンショット 2020-04-27 15.49.00.png

"I don't have a password, so I can't open it!"

solution

Modify the database.yml file under the config folder

8FDD2CC7-5986-4002-AE98-87667960AD4D.png

Enter the password you decided in "MySQL security settings" earlier ↓

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: 
  socket: /tmp/mysql.sock

Enter the password and try again http://localhost:3000/ open.

… But again an error. ↓ 3FEA6375-3D8F-4BC4-98D3-CA7AE2FEAC76.png

Unknown database ‘tomalog_development’ This time, he gets angry, "I don't know the database about tomalog_development!". Lol

This "tomalog_development" is this part of the database.yml file earlier ↓

0EA2D7CA-B095-4AF6-AD2C-4D6E11C80C11.png

It seems that he arbitrarily defined "It's a database of development environment".

What this error says is that the database isn't in MySQL and can't be viewed!

Go check if "tomalog_development" is in MySQL.

Start SQL server and log in.

asatokensei@noMacBook-Air tomalog % mysql.server start
Starting MySQL
. SUCCESS! 
asatokensei@noMacBook-Air tomalog % mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.19 Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

To see the database list on SQL server, use the command below ↓

show databases;

When executed,

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

Yeah, it's true!

So I decided to create a tomalog_development database.

The command to create a database is

create database database name;

Try to run it.

mysql> create database tomalog_development;
Query OK, 1 row affected (0.01 sec)

Check again.

mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
| mysql               |
| performance_schema  |
| sys                 |
| tomalog_development |
+---------------------+
5 rows in set (0.01 sec)

It's done! tomalog_development has been added!

Re-challenge http: // localhost: 3000 /!

3F5F14D0-1A8A-45C3-8389-C3F7D818A0B8.png

I did it ah ah! I opened it! !! !!

Bonus: Commands that I often use personally

Launch and login in local environment ↓

mysql.server start
mysql -uroot -p
mysql.server stop

Server startup and login in a virtual environment ↓

[vagrant@localhost ~]$ sudo systemctl start mysqld.service
[vagrant@localhost tomalog]$ rails db
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> exit
Bye
[vagrant@localhost tomalog]$ 

Change password ↓

mysql> SET PASSWORD = password('New password');
Query OK, 0 rows affected, 1 warning (0.00 sec)

reference

https://style.potepan.com/articles/19020.html

[Build CentOS7 + Rails + MySQL environment on Vagrant --Qiita](https://qiita.com/kt_flcl/items/50504b125e2c4eaee23d#rails%E3%83%97%E3%83%AD%E3%82%B8% E3% 82% A7% E3% 82% AF% E3% 83% 88% E3% 82% 92% E4% BD% 9C% E6% 88% 90% E3% 81% 97% E3% 81% A6% E3% 81% BF% E3% 82% 8B)

Recommended Posts

How to install MySQL
How to install Docker
How to install docker-machine
How to install ngrok
[Rails] How to install devise
How to install Boots Faces
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
How to install JDK8-10 (Mac)
Install MySQL 5.6 on CentOS6 [How to specify the version]
[Rails] How to install Font Awesome
Rails new fails to install mysql
How to install JMeter for Mac
How to install ImageMagick on Windows 10
How to install ruby through rbenv
[How to install Spring Data Jpa]
mysql2 fails to install with bundle install
Super rough! How to install Dagger2
How to install Bootstrap in Ruby
How to install MariaDB 10.4 on CentOS 8
[Rails] How to install ImageMagick (RMajick)
Steps to install MySQL 8 on CentOS 8
[Rails] How to install Font Awesome
How to install WildFly on Ubuntu 18.04
How to install Swiper in Rails
How to deploy
How to install Play Framework 2.6 for Mac
How to install Eclipse (Photon) on Mac
How to install production Metabase on Ubuntu
How to install beta php8.0 on CentOS8
How to use MySQL in Rails tutorial
How to install kafkacat on Amazon Linux2
How to develop OpenSPIFe
How to use Map
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to install network drivers on standalone Ubuntu
How to use map
[Java] Connect to MySQL
How to use collection_select
How to install Titan2D (v4.2.0) in virtual environment
How to install NVIDIA driver on Ubuntu 18.04 (Note)
How to adapt Bootstrap
How to use Twitter4J
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
How to write dockerfile
How to uninstall Rails
How to make shaded-jar
How to write docker-compose
How to use identity
How to use hashes
How to write Mockito
Note how to rollback Mysql deployed on Heroku
How to install multiple JDKs on Ubuntu 18.04 LTS
How to create docker-compose