% brew install mysql
(中略)
==> Summary
🍺 /usr/local/Cellar/mysql/8.0.27: 304 files, 294MB
==> Caveats
==> mysql
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To restart mysql after an upgrade:
brew services restart mysql
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql
% brew install mysql
(中略)
==> Summary
🍺 /usr/local/Cellar/mysql/8.0.27: 304 files, 294MB
==> Caveats
==> mysql
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To restart mysql after an upgrade:
brew services restart mysql
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql
終わった後、またバージョンを確認して出てくれば無事入っている。
セキュリティ設定:rootユーザーへのパスワードの設定
インストール時の情報には
We’ve installed your MySQL database without a root password. To secure it run: mysql_secure_installation
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No:
Please set the password for root here.
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No):
... skipping.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No):
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No):
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No):
... skipping.
All done!
% mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No:
Please set the password for root here.
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) :
... skipping.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
... skipping.
All done!
% mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No:
Please set the password for root here.
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) :
... skipping.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
... skipping.
All done!
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
% brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
% brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
続いて”mysql -u root -p”と入力してmysqlを起動。
このコマンド mysql -u root -p は “-u:ユーザー”はroot、”-p:パスワード”は設定したパスワード、で起動を意味している。 パスワードを設定していなければ、”mysql -u root”で起動できる。
すると起動して下記画面になる。
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
% mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 Homebrew
Copyright(c)2000, 2021, Oracle and/or its affiliates.
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 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 Homebrew
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 Homebrew
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
因みに、 パスワードについて、今回の様に”-p”と入力したらパスワードを聞かれ、マスクされた、入力文字が見えない状況で入力する。 他にも”–password=”もあり、 % mysql -u root –password=(設定したパスワード直打ち) と入力しても起動できる。 しかし、これは安全性が低下するのでお勧めしない。
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> USE item_list
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> USE item_list
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> DESCRIBE items;
+-------+------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| name | text | YES | | NULL | |
+-------+------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> DESCRIBE items;
+-------+------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| name | text | YES | | NULL | |
+-------+------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
今さっき出力したけれど、テーブルのデータはSELECT文で確認。
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql> SELECT * from items;
+----+-----------------+
| id | name |
+----+-----------------+
|1| きゅうり |
|2| とまと |
|3| じゃがいも |
|4| なす |
+----+-----------------+
4 rows inset(0.01 sec)</pre>
mysql> SELECT * from items;
+----+-----------------+
| id | name |
+----+-----------------+
| 1 | きゅうり |
| 2 | とまと |
| 3 | じゃがいも |
| 4 | なす |
+----+-----------------+
4 rows in set (0.01 sec)</pre>
mysql> SELECT * from items;
+----+-----------------+
| id | name |
+----+-----------------+
| 1 | きゅうり |
| 2 | とまと |
| 3 | じゃがいも |
| 4 | なす |
+----+-----------------+
4 rows in set (0.01 sec)</pre>
コメント
[…] Node.jsでWebアプリケーションを作る際の、データベース(MySQL)準備の備忘録 […]
[…] […]