shari-sushi / 0025Linux

0 stars 0 forks source link

Re: GCE VM で V-Karaoke を立てる #4

Open shari-sushi opened 4 months ago

shari-sushi commented 4 months ago

VMインスタンスをubuntuで作成

 ls
~$ cd ..
/home$ ls
*** ubuntu  
/home$ cd ..
/$ ls
bin   dev  home  lib32  libx32      media  opt   root  sbin  srv  tmp  var
boot  etc  lib   lib64  lost+found  mnt    proc  run   snap  sys  usr
/$ ls var
backups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp
/$ cd var/local
/var/local$ ls
/var/local$ ls -a
.  ..

※上述の***はsshキーが用意されてるユーザー(自分を含む開発担当)

Goインストール

$ sudo snap install go --classic
go 1.22.2 from Canonical✓ installed

MySQL

Details

```sh $ sudo apt-get install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0 Suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca The following NEW packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0 0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded. Need to get 36.8 MB of archives. After this operation, 318 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mysql-common all 5.8+1.0.5ubuntu2 [7496 B] Get:2 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-core-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [5084 kB] Get:3 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [22.0 kB] Get:4 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libevent-core-2.1-7 amd64 2.1.11-stable-1 [89.1 kB] Get:5 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libevent-pthreads-2.1-7 amd64 2.1.11-stable-1 [7372 B] Get:6 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB] Get:7 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libnuma1 amd64 2.0.12-1 [20.8 kB] Get:8 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-core-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [22.7 MB] Get:9 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [1326 kB] Get:10 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-tagset-perl all 3.20-4 [12.5 kB] Get:11 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 liburi-perl all 1.76-2 [77.5 kB] Get:12 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-parser-perl amd64 3.72-5 [86.3 kB] Get:13 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libcgi-pm-perl all 4.46-1 [186 kB] Get:14 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libfcgi-perl amd64 0.79-1 [33.1 kB] Get:15 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libcgi-fast-perl all 1:2.15-1 [10.5 kB] Get:16 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libencode-locale-perl all 1.05-1 [12.3 kB] Get:17 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB] Get:18 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libtimedate-perl all 2.3200-1 [34.0 kB] Get:19 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhttp-date-perl all 6.05-1 [9920 B] Get:20 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libio-html-perl all 1.001-1 [14.9 kB] Get:21 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 liblwp-mediatypes-perl all 6.04-1 [19.5 kB] Get:22 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhttp-message-perl all 6.22-1 [76.1 kB] Get:23 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-utils amd64 0.996-10build1 [4912 B] Get:24 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic all 2.7.0-20070801+main-2.1 [6714 kB] Get:25 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic-utf8 all 2.7.0-20070801+main-2.1 [4380 B] Get:26 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server all 8.0.36-0ubuntu0.20.04.1 [9484 B] Fetched 36.8 MB in 1s (34.0 MB/s) Preconfiguring packages ... Selecting previously unselected package mysql-common. (Reading database ... 62124 files and directories currently installed.) Preparing to unpack .../0-mysql-common_5.8+1.0.5ubuntu2_all.deb ... Unpacking mysql-common (5.8+1.0.5ubuntu2) ... Selecting previously unselected package mysql-client-core-8.0. Preparing to unpack .../1-mysql-client-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package mysql-client-8.0. Preparing to unpack .../2-mysql-client-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libevent-core-2.1-7:amd64. Preparing to unpack .../3-libevent-core-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libevent-pthreads-2.1-7:amd64. Preparing to unpack .../4-libevent-pthreads-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libmecab2:amd64. Preparing to unpack .../5-libmecab2_0.996-10build1_amd64.deb ... Unpacking libmecab2:amd64 (0.996-10build1) ... Selecting previously unselected package libnuma1:amd64. Preparing to unpack .../6-libnuma1_2.0.12-1_amd64.deb ... Unpacking libnuma1:amd64 (2.0.12-1) ... Selecting previously unselected package mysql-server-core-8.0. Preparing to unpack .../7-mysql-server-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-common (5.8+1.0.5ubuntu2) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Selecting previously unselected package mysql-server-8.0. (Reading database ... 62345 files and directories currently installed.) Preparing to unpack .../00-mysql-server-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libhtml-tagset-perl. Preparing to unpack .../01-libhtml-tagset-perl_3.20-4_all.deb ... Unpacking libhtml-tagset-perl (3.20-4) ... Selecting previously unselected package liburi-perl. Preparing to unpack .../02-liburi-perl_1.76-2_all.deb ... Unpacking liburi-perl (1.76-2) ... Selecting previously unselected package libhtml-parser-perl. Preparing to unpack .../03-libhtml-parser-perl_3.72-5_amd64.deb ... Unpacking libhtml-parser-perl (3.72-5) ... Selecting previously unselected package libcgi-pm-perl. Preparing to unpack .../04-libcgi-pm-perl_4.46-1_all.deb ... Unpacking libcgi-pm-perl (4.46-1) ... Selecting previously unselected package libfcgi-perl. Preparing to unpack .../05-libfcgi-perl_0.79-1_amd64.deb ... Unpacking libfcgi-perl (0.79-1) ... Selecting previously unselected package libcgi-fast-perl. Preparing to unpack .../06-libcgi-fast-perl_1%3a2.15-1_all.deb ... Unpacking libcgi-fast-perl (1:2.15-1) ... Selecting previously unselected package libencode-locale-perl. Preparing to unpack .../07-libencode-locale-perl_1.05-1_all.deb ... Unpacking libencode-locale-perl (1.05-1) ... Selecting previously unselected package libhtml-template-perl. Preparing to unpack .../08-libhtml-template-perl_2.97-1_all.deb ... Unpacking libhtml-template-perl (2.97-1) ... Selecting previously unselected package libtimedate-perl. Preparing to unpack .../09-libtimedate-perl_2.3200-1_all.deb ... Unpacking libtimedate-perl (2.3200-1) ... Selecting previously unselected package libhttp-date-perl. Preparing to unpack .../10-libhttp-date-perl_6.05-1_all.deb ... Unpacking libhttp-date-perl (6.05-1) ... Selecting previously unselected package libio-html-perl. Preparing to unpack .../11-libio-html-perl_1.001-1_all.deb ... Unpacking libio-html-perl (1.001-1) ... Selecting previously unselected package liblwp-mediatypes-perl. Preparing to unpack .../12-liblwp-mediatypes-perl_6.04-1_all.deb ... Unpacking liblwp-mediatypes-perl (6.04-1) ... Selecting previously unselected package libhttp-message-perl. Preparing to unpack .../13-libhttp-message-perl_6.22-1_all.deb ... Unpacking libhttp-message-perl (6.22-1) ... Selecting previously unselected package mecab-utils. Preparing to unpack .../14-mecab-utils_0.996-10build1_amd64.deb ... Unpacking mecab-utils (0.996-10build1) ... Selecting previously unselected package mecab-ipadic. Preparing to unpack .../15-mecab-ipadic_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mecab-ipadic-utf8. Preparing to unpack .../16-mecab-ipadic-utf8_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../17-mysql-server_8.0.36-0ubuntu0.20.04.1_all.deb ... Unpacking mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libmecab2:amd64 (0.996-10build1) ... Setting up mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libhtml-tagset-perl (3.20-4) ... Setting up liblwp-mediatypes-perl (6.04-1) ... Setting up libencode-locale-perl (1.05-1) ... Setting up mecab-utils (0.996-10build1) ... Setting up libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libio-html-perl (1.001-1) ... Setting up libtimedate-perl (2.3200-1) ... Setting up libnuma1:amd64 (2.0.12-1) ... Setting up mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libfcgi-perl (0.79-1) ... Setting up liburi-perl (1.76-2) ... Setting up libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libhttp-date-perl (6.05-1) ... Setting up mecab-ipadic (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up libhtml-parser-perl (3.72-5) ... Setting up libhttp-message-perl (6.22-1) ... Setting up mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Renaming removed key_buffer and myisam-recover options (if present) mysqld will log errors to /var/log/mysql/error.log mysqld is running as pid 2883 Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up libcgi-pm-perl (4.46-1) ... Setting up libhtml-template-perl (2.97-1) ... Setting up mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libcgi-fast-perl (1:2.15-1) ... Processing triggers for systemd (245.4-4ubuntu3.23) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.15) ... ```

posswordは出力されなかった。

公式見返してみると、

インストール中に、MySQL インストールの root ユーザーのパスワードを入力するように求められます。

ha???求められてないが?

$ sudo snap install tree
$ tree 1.8.0+pkg-3fd6 from 林博仁(Buo-ren, Lin) (brlin) installed
$ tree . | grep *mysql* | cat kawai-mysql-grep.txt
shari-sushi commented 4 months ago

ワカランすぎる AI様の言う通り

$ sudo systemctl stop mysql
:/etc/mysql$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
:/etc/mysql$ sudo killall mysqld
mysqld: no process found
:/etc/mysql$ cd ..
:/etc$ cd ..
:/$ ls
bin   dev  home  lib32  libx32      media  opt   root  sbin  srv  tmp  var
boot  etc  lib   lib64  lost+found  mnt    proc  run   snap  sys  usr
:/$ ls var
backups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp
:/$ ls lib
mysql 他は略
:/$ ls mysql-files
ls: cannot access 'mysql-files': No such file or directory
:/$ sudo mkdir mysql-files
:/$ cd ..
:/$ cd ..
:/$ ls
bin   dev  home  lib32  libx32      media  mysql-files  proc  run   snap  sys  usr
boot  etc  lib   lib64  lost+found  mnt    opt          root  sbin  srv   tmp  var
:/$ sudo chown mysql:mysql /var/lib/mysql-files
:/$ sudo mysql_install_db --user=mysql --datadir=/var/lib/mysql-files
sudo: mysql_install_db: command not found
:/$ sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo: mysql_install_db: command not found

ここで詰まる。

要はmysqlを停止させたい。

https://qiita.com/hit/items/42cfcb28aa988b5a16f7

:/$  ps -efw | grep -i mysql
my_acc_name+   20811    2291  0 15:37 pts/1    00:00:00 grep --color=auto -i mysql
$ ps -aux | grep mysql
susi_im+   20821  0.0  0.0   8168   656 pts/1    S+   15:42   0:00 grep --color=auto mysql

プロセスは動いてない。

/etc/init.d$ ./mysql stop
Stopping mysql (via systemctl): mysql.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'mysql.service'.
Authenticating as: Ubuntu (ubuntu)
Password: 
0polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Failed to stop mysql.service: Access denied
See system logs and 'systemctl st

パスワードが分からないっちゅうに。

shari-sushi commented 4 months ago

MySQL

MySQLいろいろあった

Details

Details

```sh $ sudo apt-get install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0 Suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca The following NEW packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0 0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded. Need to get 36.8 MB of archives. After this operation, 318 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mysql-common all 5.8+1.0.5ubuntu2 [7496 B] Get:2 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-core-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [5084 kB] Get:3 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [22.0 kB] Get:4 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libevent-core-2.1-7 amd64 2.1.11-stable-1 [89.1 kB] Get:5 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libevent-pthreads-2.1-7 amd64 2.1.11-stable-1 [7372 B] Get:6 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB] Get:7 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libnuma1 amd64 2.0.12-1 [20.8 kB] Get:8 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-core-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [22.7 MB] Get:9 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [1326 kB] Get:10 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-tagset-perl all 3.20-4 [12.5 kB] Get:11 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 liburi-perl all 1.76-2 [77.5 kB] Get:12 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-parser-perl amd64 3.72-5 [86.3 kB] Get:13 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libcgi-pm-perl all 4.46-1 [186 kB] Get:14 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libfcgi-perl amd64 0.79-1 [33.1 kB] Get:15 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libcgi-fast-perl all 1:2.15-1 [10.5 kB] Get:16 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libencode-locale-perl all 1.05-1 [12.3 kB] Get:17 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB] Get:18 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libtimedate-perl all 2.3200-1 [34.0 kB] Get:19 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhttp-date-perl all 6.05-1 [9920 B] Get:20 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libio-html-perl all 1.001-1 [14.9 kB] Get:21 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 liblwp-mediatypes-perl all 6.04-1 [19.5 kB] Get:22 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhttp-message-perl all 6.22-1 [76.1 kB] Get:23 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-utils amd64 0.996-10build1 [4912 B] Get:24 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic all 2.7.0-20070801+main-2.1 [6714 kB] Get:25 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic-utf8 all 2.7.0-20070801+main-2.1 [4380 B] Get:26 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server all 8.0.36-0ubuntu0.20.04.1 [9484 B] Fetched 36.8 MB in 1s (34.0 MB/s) Preconfiguring packages ... Selecting previously unselected package mysql-common. (Reading database ... 62124 files and directories currently installed.) Preparing to unpack .../0-mysql-common_5.8+1.0.5ubuntu2_all.deb ... Unpacking mysql-common (5.8+1.0.5ubuntu2) ... Selecting previously unselected package mysql-client-core-8.0. Preparing to unpack .../1-mysql-client-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package mysql-client-8.0. Preparing to unpack .../2-mysql-client-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libevent-core-2.1-7:amd64. Preparing to unpack .../3-libevent-core-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libevent-pthreads-2.1-7:amd64. Preparing to unpack .../4-libevent-pthreads-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libmecab2:amd64. Preparing to unpack .../5-libmecab2_0.996-10build1_amd64.deb ... Unpacking libmecab2:amd64 (0.996-10build1) ... Selecting previously unselected package libnuma1:amd64. Preparing to unpack .../6-libnuma1_2.0.12-1_amd64.deb ... Unpacking libnuma1:amd64 (2.0.12-1) ... Selecting previously unselected package mysql-server-core-8.0. Preparing to unpack .../7-mysql-server-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-common (5.8+1.0.5ubuntu2) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Selecting previously unselected package mysql-server-8.0. (Reading database ... 62345 files and directories currently installed.) Preparing to unpack .../00-mysql-server-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libhtml-tagset-perl. Preparing to unpack .../01-libhtml-tagset-perl_3.20-4_all.deb ... Unpacking libhtml-tagset-perl (3.20-4) ... Selecting previously unselected package liburi-perl. Preparing to unpack .../02-liburi-perl_1.76-2_all.deb ... Unpacking liburi-perl (1.76-2) ... Selecting previously unselected package libhtml-parser-perl. Preparing to unpack .../03-libhtml-parser-perl_3.72-5_amd64.deb ... Unpacking libhtml-parser-perl (3.72-5) ... Selecting previously unselected package libcgi-pm-perl. Preparing to unpack .../04-libcgi-pm-perl_4.46-1_all.deb ... Unpacking libcgi-pm-perl (4.46-1) ... Selecting previously unselected package libfcgi-perl. Preparing to unpack .../05-libfcgi-perl_0.79-1_amd64.deb ... Unpacking libfcgi-perl (0.79-1) ... Selecting previously unselected package libcgi-fast-perl. Preparing to unpack .../06-libcgi-fast-perl_1%3a2.15-1_all.deb ... Unpacking libcgi-fast-perl (1:2.15-1) ... Selecting previously unselected package libencode-locale-perl. Preparing to unpack .../07-libencode-locale-perl_1.05-1_all.deb ... Unpacking libencode-locale-perl (1.05-1) ... Selecting previously unselected package libhtml-template-perl. Preparing to unpack .../08-libhtml-template-perl_2.97-1_all.deb ... Unpacking libhtml-template-perl (2.97-1) ... Selecting previously unselected package libtimedate-perl. Preparing to unpack .../09-libtimedate-perl_2.3200-1_all.deb ... Unpacking libtimedate-perl (2.3200-1) ... Selecting previously unselected package libhttp-date-perl. Preparing to unpack .../10-libhttp-date-perl_6.05-1_all.deb ... Unpacking libhttp-date-perl (6.05-1) ... Selecting previously unselected package libio-html-perl. Preparing to unpack .../11-libio-html-perl_1.001-1_all.deb ... Unpacking libio-html-perl (1.001-1) ... Selecting previously unselected package liblwp-mediatypes-perl. Preparing to unpack .../12-liblwp-mediatypes-perl_6.04-1_all.deb ... Unpacking liblwp-mediatypes-perl (6.04-1) ... Selecting previously unselected package libhttp-message-perl. Preparing to unpack .../13-libhttp-message-perl_6.22-1_all.deb ... Unpacking libhttp-message-perl (6.22-1) ... Selecting previously unselected package mecab-utils. Preparing to unpack .../14-mecab-utils_0.996-10build1_amd64.deb ... Unpacking mecab-utils (0.996-10build1) ... Selecting previously unselected package mecab-ipadic. Preparing to unpack .../15-mecab-ipadic_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mecab-ipadic-utf8. Preparing to unpack .../16-mecab-ipadic-utf8_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../17-mysql-server_8.0.36-0ubuntu0.20.04.1_all.deb ... Unpacking mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libmecab2:amd64 (0.996-10build1) ... Setting up mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libhtml-tagset-perl (3.20-4) ... Setting up liblwp-mediatypes-perl (6.04-1) ... Setting up libencode-locale-perl (1.05-1) ... Setting up mecab-utils (0.996-10build1) ... Setting up libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libio-html-perl (1.001-1) ... Setting up libtimedate-perl (2.3200-1) ... Setting up libnuma1:amd64 (2.0.12-1) ... Setting up mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libfcgi-perl (0.79-1) ... Setting up liburi-perl (1.76-2) ... Setting up libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libhttp-date-perl (6.05-1) ... Setting up mecab-ipadic (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up libhtml-parser-perl (3.72-5) ... Setting up libhttp-message-perl (6.22-1) ... Setting up mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Renaming removed key_buffer and myisam-recover options (if present) mysqld will log errors to /var/log/mysql/error.log mysqld is running as pid 2883 Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up libcgi-pm-perl (4.46-1) ... Setting up libhtml-template-perl (2.97-1) ... Setting up mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libcgi-fast-perl (1:2.15-1) ... Processing triggers for systemd (245.4-4ubuntu3.23) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.15) ... ```

posswordは出力されなかった。 公式見返してみると、 ``` インストール中に、MySQL インストールの root ユーザーのパスワードを入力するように求められます。 ``` ha???求められてないが? ``` $ sudo snap install tree $ tree 1.8.0+pkg-3fd6 from 林博仁(Buo-ren, Lin) (brlin) installed ``` ``` $ tree . | grep *mysql* | cat kawai-mysql-grep.txt ``` 公式ドキュメントでたらいまわしにされたあげくよくわからず。
Details

``` /var/log/mysql$ cat error.log | grep password 2024-05-07T15:48:43.240044Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. ```

ログイン

sudo mysql -u root

で入れた。orz

https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql-ja

注: このチュートリアルでMySQLシェル内にユーザーを追加する場合、ユーザーのホストをサーバーのIPアドレスではなく、localhostとして指定します 。localhostは「このコンピューター」を意味するホスト名で、MySQLはこの特定のホスト名を特別に扱います。 そのホストを持つユーザーがMySQLにログインすると、Unixソケットファイルを使用してローカルサーバーに接続しようとします。したがって、通常、サーバーにSSHで接続する場合、またはローカルmysqlクライアントを実行してローカルMySQLサーバーに接続する場合に、localhostが使用されます。

ユーザー管理

Goの接続でsudoできるとも思えない。 こんかいはテストしてすぐ落とすのでdbのセキュリティ面はなんでも良いので、rootのパスワードちゃんとしたい。 5.7だけど…。sudo使わないrootユーザーのログイン

ALTER USER 'root'@'localhost' IDENTIFIED BY '[password]';

でも本番環境想定なら↓とすべき。

CREATE USER '[user_name]'@'localhost' IDENTIFIED BY '[password]';

※その後、パスワード変更しようとしたらshari0000が通らなくなってる。drop userして作り直そうとしてもダメ。再起動時にバリデーション設定が変わった? https://dev.mysql.com/doc/refman/8.0/ja/validate-password.html https://qiita.com/hermannsw/items/b4da81201d69cefb080b

SET GLOBAL validate_password_policy=LOW;

公式的に8.0はこっちか? validate_password.policy

SET GLOBAL validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)

できたわ。何このマイナーチェンジ…。

IPアドレスとlocalhost、passwordのバリデーション

- IPについて - [MySQLでlocalhostと127.0.0.1の違い](https://qiita.com/TanukiTam/items/f6a08740d0fcda0db7be) - 今回は`localhost`とした。 - これはMySQLでは特に特別視されているようで、`127.0.0.1`とは扱いが違うらしい。 何とかソケットを使って接続している…。 - これがバックエンドから処理する際は、localhostと書いていても、内部処理で`127.0.0.1`に変換される可能性がある。その場合は、MySQL側で`127.0.0.1`のユーザーを作成する必要がある。 - PC上やDocker上のMySQLでは`localhost`で接続できていたので完全に落とし穴。 - passwordのバリデーションについて > LOW Length >= 8 > MEDIUM Length >= 8, numeric, mixed case, and special characters > STRONG Length >= 8, numeric, mixed case, special characters and dictionary
の3段階のバリデーションが用意されている様子で、デフォルトはLOWと思われる。 ↓3段階あるソース(作業ログ)

`sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql`

``` sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql sudo: mysql_install_db: command not found :/bin$ sudo apt-get purge mysql-server mysql-client mysql-common Reading package lists... Done Building dependency tree Reading state information... Done Package 'mysql-client' is not installed, so not removed The following packages were automatically installed and are no longer required: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-core-8.0 mysql-server-core-8.0 Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: mysql-client-8.0* mysql-common* mysql-server* mysql-server-8.0* 0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. After this operation, 1621 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 62711 files and directories currently installed.) Removing mysql-server (8.0.36-0ubuntu0.20.04.1) ... Removing mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Removing mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Removing mysql-common (5.8+1.0.5ubuntu2) ... Processing triggers for man-db (2.9.1-1) ... (Reading database ... 62668 files and directories currently installed.) Purging configuration files for mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Purging configuration files for mysql-common (5.8+1.0.5ubuntu2) ... dpkg: warning: while removing mysql-common, directory '/etc/mysql' not empty so not removed Processing triggers for systemd (245.4-4ubuntu3.23) ... :/bin$ sudo rm -rf /etc/mysql /var/lib/mysql :/bin$ sudo apt-get install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: mysql-client-8.0 mysql-common mysql-server-8.0 Suggested packages: mailx tinyca The following NEW packages will be installed: mysql-client-8.0 mysql-common mysql-server mysql-server-8.0 0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/1365 kB of archives. After this operation, 1621 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Preconfiguring packages ... Selecting previously unselected package mysql-common. (Reading database ... 62648 files and directories currently installed.) Preparing to unpack .../mysql-common_5.8+1.0.5ubuntu2_all.deb ... Unpacking mysql-common (5.8+1.0.5ubuntu2) ... Selecting previously unselected package mysql-client-8.0. Preparing to unpack .../mysql-client-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-common (5.8+1.0.5ubuntu2) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Selecting previously unselected package mysql-server-8.0. (Reading database ... 62675 files and directories currently installed.) Preparing to unpack .../mysql-server-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../mysql-server_8.0.36-0ubuntu0.20.04.1_all.deb ... Unpacking mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Renaming removed key_buffer and myisam-recover options (if present) mysqld will log errors to /var/log/mysql/error.log mysqld is running as pid 21487 Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up mysql-server (8.0.36-0ubuntu0.20.04.1) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for systemd (245.4-4ubuntu3.23) ... :/bin$ sudo 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: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Skipping password set for root as authentication with auth_socket is used by default. If you would like to use password authentication instead, this can be done with the "ALTER_USER" command. See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information. 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) : Y Success. 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) : Y Success. 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) : Y - Dropping test database... Success. - Removing privileges on test database... Success. 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) : Y Success. All done! ```

database(schema)作成

日本語や絵文字対応させたいのでutf8mb4

mysql> CREATE DATABASE v_kara_db CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
Query OK, 1 row affected (0.01 sec)

rootユーザー使わないことにしたので、権限付与 https://qiita.com/shuntaro_tamura/items/2fb114b8c5d1384648aa

grant all on v_kara_db.* to 'shari'@'localhost' identified by 'shari_sushi';

grant all on v_kara_db.* to 'shari'@'127.0.0.1 identified by 'shari_sushi';

※この1文だけでcreate userと同じ効果があるらしい。 ※create userした後だとエラーになった。↓なら通った。

grant all on v_kara_db.* to 'shari'@'localhost';
~/V-Kara-Lists/t0016Go/cmd$ go run .
path=shari:shari_sushi@tcp(localhost:3306)/v_kara_db?charset=utf8mb4&parseTime=true 
migratoin開始
2024/05/08 07:05:29 /home/myname/V-Kara-Lists/t0016Go/infra/db.go:107
[2.372ms] [rows:-] SELECT DATABASE()
.
.
.
[GIN-debug] Listening and serving HTTP on v-karaoke.com:8080
[GIN-debug] [ERROR] listen tcp 52.192.184.120:8080: bind: cannot assign requested address

通ったと思ったら、リスナーをbindできなかった…? これは次のMySQLとGoの接続にて


余談1

朝起きて、VMインスタンスを起動しようとしたら、

[インスタンス名] を開始できませんでした。Invalid value for field '': ''. Termination time must be more than 30 seconds in the future and less than 17 weeks 1 day.

とエラー。ページ更新(F5)も挟んで3回くらい試したけどダメ。 12時間で自動停止の設定にしていたのになぜ。 VMインスタンス編集で12時間を72時間にしたら起動できた。 編集画面を開いて保存の操作が良かったのか、12→72という時間をいじったことが良かったのかヨクワカラナイ。

shari-sushi commented 4 months ago

GoとMySQLの接続

https://zenn.dev/nananaoto/articles/c56bc2b38834b32c8fd7

環境変数を設定するだけで済むと思うけど、ネットで調べるとDocker前提の話ばかり出てくる。 会社ではCloud Runつかってるぽいけど…? https://zenn.dev/nananaoto/articles/c56bc2b38834b32c8fd7#%E3%83%AD%E3%83%BC%E3%82%AB%E3%83%AB%E3%81%8B%E3%82%89cloud-build%E3%82%92%E5%AE%9F%E8%A1%8C

今日中にデプロイして動作確認する(curl可)という目標ができたので、ハードコードすれば何とかなることは後回し。

いずれにせよクラウド環境でGoとMySQLをローカル接続するなんて想定はしてなかったので… コードいじってVScodeでpushして(このままviでやってもよかったけど、多分lintとか働いてないから…)、GCEのssh接続してるshellでpull githubの該当コード

git pull origin develop
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 3), reused 5 (delta 3), pack-reused 0
Unpacking objects: 100% (6/6), 1.75 KiB | 894.00 KiB/s, done.
From https://github.com/shari-sushi/V-Kara-Lists
 * branch            develop    -> FETCH_HEAD
   3d9a216..2a460a9  develop    -> origin/develop
Updating 3d9a216..2a460a9
Fast-forward
 t0016Go/infra/db.go | 13 +++++++++++--

今回のためだけのコードがあればviで直接編集した方が良いかもしれない。 ただの研修だし。

path=root:@tcp(localhost:3306)/v_kara_db?charset=utf8mb4&parseTime=true 

2024/05/08 06:38:17 /home/myname/V-Kara-Lists/t0016Go/infra/db.go:92
[error] failed to initialize database, got error Error 1698 (28000): Access denied for user 'root'@'localhost'
panic: failed to connect database

さあ、sudoできないからダメなのか、localhostだからだめなのか。

$ sudo mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.36-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2024, 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> CREATE USER 'shari'@'127.0.0.1' IDENTIFIED BY 'shari_sushi';
Query OK, 0 rows affected (0.10 sec)

結論、localhostのままで行けたと思う。

~/V-Kara-Lists/t0016Go/cmd$ go run .
path=shari:shari_sushi@tcp(localhost:3306)/v_kara_db?charset=utf8mb4&parseTime=true 
migratoin開始
2024/05/08 07:05:29 /home/myname/V-Kara-Lists/t0016Go/infra/db.go:107
[2.372ms] [rows:-] SELECT DATABASE()
.
.
.
[GIN-debug] Listening and serving HTTP on v-karaoke.com:8080
[GIN-debug] [ERROR] listen tcp 52.192.184.120:8080: bind: cannot assign requested address

db接続はできた。でもリスナーをbindできなかったとかでサーバーは起動しなかったぽい。

mysql> select user, host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
| shari            | localhost |
+------------------+-----------+
shari-sushi commented 4 months ago

Next.js

Next.jsの起動準備

そっかnpm, npxってnode.jsのコマンドか。

Ubuntu 20.04にNode.jsをインストールする方法

sudo apt install nodejs

$ sudo apt install nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package nodejs

https://qiita.com/deBroglieeeen/items/8aabc522df807abe3988#%E5%8E%9F%E5%9B%A0

原因

インストール元を指定してあげないとnodejsのみをインストールしてしまってnpm等のパッケージをよしなにインストールしてくれない。

バージョンが古かったようで怒られた(5年前の記事だもんな…)

```sh $ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - ================================================================================ ================================================================================ DEPRECATION WARNING Node.js 10.x is no longer actively supported! You will not receive security or critical stability updates for this version. You should migrate to a supported version of Node.js as soon as possible. Use the installation script that corresponds to the version of Node.js you wish to install. e.g. * https://deb.nodesource.com/setup_16.x — Node.js 16 "Gallium" * https://deb.nodesource.com/setup_18.x — Node.js 18 LTS "Hydrogen" (recommended) * https://deb.nodesource.com/setup_19.x — Node.js 19 "Nineteen" * https://deb.nodesource.com/setup_20.x — Node.js 20 "Iron" (current) Please see https://github.com/nodejs/Release for details about which version may be appropriate for you. The NodeSource Node.js distributions repository contains information both about supported versions of Node.js and supported Linux distributions. To learn more about usage, see the repository: https://github.com/nodesource/distributions ================================================================================ ================================================================================ Continuing in 20 seconds ... ^C ```

なるほど。 ローカルPCのバージョンと同じにすることにした。

>node -v
v20.9.0
バージョン部分変えて試してみた

```sh ~$ curl -sL https://deb.nodesource.com/setup_20.9.0 | sudo -E bash - bash: line 1: syntax error near unexpected token `newline' bash: line 1: `' ~$ curl -sL https://deb.nodesource.com/setup_20.9 | sudo -E bash - bash: line 1: syntax error near unexpected token `newline' bash: line 1: `' ~$ curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash - 2024-05-08 03:32:06 - Installing pre-requisites ~$ curl -sL https://deb.nodesource.com/setup_20.9.0 | sudo -E bash - bash: line 1: syntax error near unexpected token `newline' bash: line 1: `' ~$ curl -sL https://deb.nodesource.com/setup_20.9 | sudo -E bash - bash: line 1: syntax error near unexpected token `newline' bash: line 1: `' ```

この書き方じゃないとダメみたい。

~$ curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
2024-05-08 03:32:06 - Installing pre-requisites
~$ sudo apt-get install nodejs -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 31.6 MB of archives.
After this operation, 196 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_20.x nodistro/main amd64 nodejs amd64 20.13.0-1nodesource1 [31.6 MB]
Fetched 31.6 MB in 1s (27.7 MB/s)  
Selecting previously unselected package nodejs.
(Reading database ... 62715 files and directories currently installed.)
Preparing to unpack .../nodejs_20.13.0-1nodesource1_amd64.deb ...
Unpacking nodejs (20.13.0-1nodesource1) ...
Setting up nodejs (20.13.0-1nodesource1) ...
Processing triggers for man-db (2.9.1-1) ...
$ node -v
v20.13.0

まあ、そりゃ新しいのが入るよね。

ではnpm系をgit cloneした時のお作法 ※package.jsonとかがあるディレクトリかそれ以下でやるんだったか。

~/V-Kara-Lists/t0016Next/myapp/src$ npm install

起動

VSCodeだとこうなる。

\src>npm run 
dev

> 0016api@0.1.0 dev
> next dev -p 80   

  ▲ Next.js 13.5.6
  - Local:        http://localhost:80

 ✓ Ready in 4.2s

GCE VMインスタンス shel(要はubuntu?)だとこうなった。

/src$ npm run dev

> 0016api@0.1.0 dev
> next dev -p 80

sh: 1: next: not found

とりあえずnpm updateをやってみている。 これさ…node_modueが重すぎる説ある?

https://github.com/reworkd/AgentGPT/issues/179 npm install


余談1 そういえば、 apt-getの-yは途中でY/nを求められた際にはYと自動で回答するようなオプションらしい。

余談2 npm installが何回か止まったから、ssh接続落としてやり直した。 その際、npm installの影響でnode_moduleができてしまっていて(当たり前だが)、改めてnpm installしてもエラーとなった。 なので削除してやり直した。

shari-sushi commented 4 months ago

[GIN-debug] [ERROR] listen tcp 52.192.184.120:8080: bind: cannot assign requested address

について、

8080が使われてる可能性を潰した。

```sh $ sudo apt install net-tools ``` からの ``` $ sudo netstat -tnlp | grep :8080 $ sudo netstat -tnlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 737/sshd: /usr/sbin tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 715/mysqld tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 454/systemd-resolve tcp 0 0 127.0.0.1:33060 0.0.0.0:* LISTEN 715/mysqld tcp6 0 0 :::22 :::* LISTEN 737/sshd: /usr/sbin ```

shari-sushi commented 4 months ago

疲れたのでここまでのまとめ

shari-sushi commented 4 months ago

npm installがフリーズしてた件

topコマンドで見たら、cpu100%使って頑張ってた VMインスタンスのスペックを最小にしてたので、スペックアップ。

一旦マシン停止して、編集 マシンタイプ e2-standard-8 8cpu(4コア), メモリ32GB

shari-sushi commented 4 months ago

完了()

golang : 8080でサーバーが立たない。IPアドレスはじかれてる説ある。 → Goのコードで localhost:8080でサーバーを立てていたのを、0.0.0.0:8080で立て直したら解決。(Dockerかなにかでもこんなことあった。) next : npm installが正常に完了したかわからない。 → してなかったぽい。原因はマシンのスペック不足。スペック上げて、node_module消して、再度npm install。 その後、sudo npm run dev

でmysqlに色々データぶち込んで…

ぶち込んだデータ

vtubers ```sql INSERT INTO vtubers (vtuber_id, vtuber_name, vtuber_kana, intro_movie_url, vtuber_inputter_id) VALUE (1, "妹望おいも", "imomochi_oimo", "", 1), (2, "ChumuNote", "chumu_note", "", 1), (3, "現実みろ", "real_miro", "", 1), (4, "宝鐘マリン", "houshou_marin", "", 1), (5, "星街すいせい", "hosimachi_suisei", "", 1) ; ``` movies ```sql INSERT INTO movies ( movie_url, movie_title, vtuber_id, movie_inputter_id) VALUE ("www.youtube.com/watch?v=AlHRqSsF--8", "【歌枠リレー】歌う【妹望おいも】", 1, 1), ("www.youtube.com/watch?v=5WzeYsoGCZc", "[ 耐久歌枠 ]Ch登録3000人めざしてうたいます♪", 3, 1), ``` ``` INSERT INTO movies ( movie_url, movie_title, vtuber_id, movie_inputter_id) VALUE ("www.youtube.com/watch?v=-2XIB4OxcbM", "【歌枠】50代の選曲をしてしまうマリン船長【ホロライブ/宝鐘マリン】", 4, 1), ("www.youtube.com/watch?v=-b-HQcwrLQ4", "【歌】詰め合わせ(1)【妹望おいも】", 1, 1), ("www.youtube.com/watch?v=3aNvEghsmYY", "【歌枠】好きな曲歌う【妹望おいも】", 1, 1), ("www.youtube.com/watch?v=5WzeYsoGCZc", "[ 耐久歌枠 ]Ch登録3000人めざしてうたいます♪", 3, 1), ("www.youtube.com/watch?v=7xHFtgfHJcA", "【歌枠】SINGING STREAM volumeUPver.【ホロライブ / 星街すいせい】", 5, 1), ("www.youtube.com/watch?v=AlHRqSsF--8", "【歌枠リレー】歌う【妹望おいも】", 1, 1), ("www.youtube.com/watch?v=h_FqVVAs2rE", "【歌ってみた】選曲がナウすぎて10代の可能性が浮上するマリン船長【ホロライブ/宝鐘マリン】", 4, 1), ("www.youtube.com/watch?v=TosxazFAHu0", "【#歌枠】アニソン歌枠!懐かしい曲も歌うよ~【妹望おいも】", 1, 1), ("www.youtube.com/watch?v=4JIbhFoOMOc", "デモ動画(仮)", 6, 1); ``` みたいな感じ。

curl http://localhost:80

したら、入力したデータが返ってきた。

これで、外向けにはしてないけど、一応デプロイはできた。 実際に使えるようにするなら、LBとかファイアウォールとかもやらないといけないけど、今回はまあ。