mysql データベース メモ2

データベースで設定されているデフォルトの文字コード


mysql> SELECT * FROM INFORMATION_SCHEMA.SCHEMATA;
で得られるらしい。
面倒だ。

他の文字コードに変更するには


mysql> alter database horserace CHARACTER SET utf8
多分設定上だけで中身は変わってない(latin1とか)だと思う。

[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

【送料無料】 詳細!PHP7+MySQL入門ノート / 大重美幸 【本】
価格:3218円(税込、送料無料) (2018/9/21時点)


php インストール

phpの他にパッケージ等が使えなかったので、メモ。

xmlのパッケージが7依存だったので消して古いのを入れ直す。


$ sudo apt remove php-xml
$ sudo apt install php5.6-xml

pear のHttp_Clientを入れようとしたらかわってるよと言われた・・・


$ pear install Http_Client
WARNING: "pear/HTTP_Client" is deprecated in favor of "pear/HTTP_Request2"
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
Cannot install, php_dir for channel "pear.php.net" is not writeable by the current user
なのでデータベースを新しくして新しいのを入れた。

sudo pear channel-update pear.php.net
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
$ sudo pear install Http_Request2
pear/HTTP_Request2 can optionally use PHP extension "curl"
downloading HTTP_Request2-2.3.0.tgz ...
Starting to download HTTP_Request2-2.3.0.tgz (119,717 bytes)
.................done: 119,717 bytes
downloading Net_URL2-2.2.1.tgz ...
Starting to download Net_URL2-2.2.1.tgz (20,010 bytes)
...done: 20,010 bytes
install ok: channel://pear.php.net/Net_URL2-2.2.1
install ok: channel://pear.php.net/HTTP_Request2-2.3.0
多分 Http_Request2 は明示的に入れなくても

$ sudo pear install Http_Client
WARNING: "pear/HTTP_Client" is deprecated in favor of "pear/HTTP_Request2"
WARNING: "pear/HTTP_Request" is deprecated in favor of "pear/HTTP_Request2"
WARNING: "pear/Net_URL" is deprecated in favor of "pear/Net_URL2"
downloading HTTP_Client-1.2.1.tgz ...
Starting to download HTTP_Client-1.2.1.tgz (10,269 bytes)
.....done: 10,269 bytes
downloading HTTP_Request-1.4.4.tgz ...
Starting to download HTTP_Request-1.4.4.tgz (17,233 bytes)
...done: 17,233 bytes
downloading Net_URL-1.0.15.tgz ...
Starting to download Net_URL-1.0.15.tgz (6,393 bytes)
...done: 6,393 bytes
downloading Net_Socket-1.2.2.tgz ...
Starting to download Net_Socket-1.2.2.tgz (6,903 bytes)
...done: 6,903 bytes
install ok: channel://pear.php.net/Net_URL-1.0.15
install ok: channel://pear.php.net/Net_Socket-1.2.2
install ok: channel://pear.php.net/HTTP_Request-1.4.4
install ok: channel://pear.php.net/HTTP_Client-1.2.1
で自動的にチェックして入れてくれるはず。


[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

【送料無料】 詳細!PHP7+MySQL入門ノート / 大重美幸 【本】
価格:3218円(税込、送料無料) (2018/9/21時点)


mysql データベース メモ

接続(Windows


D:\xxxxxx> mysql.exe -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.1.19-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

データベース一覧・・・


MariaDB [(none)]> SHOW DATABASES;

                                          • +
Database
                                          • +
horserace
information_schema
mysql
performance_schema
phpmyadmin
test
                                          • +

6 rows in set (0.00 sec)

horseraceにはどんなテーブルがあるのか・・・


MariaDB [(none)]> SHOW tables from horserace;

                                            • +
Tables_in_horserace
                                            • +
horse_races
race_results
race_results_harai
races
                                            • +

4 rows in set (0.00 sec)

horserace に接続して・・・


MariaDB [(none)]> use horserace;
Database changed

race_resultsテーブルの設定を見てみる・・・


MariaDB [horserace]> SHOW create table race_results;

                                                            • -


) ENGINE=InnoDB DEFAULT CHARSET=sjis |

テーブル一個一個にcharset が設定できるとか、きめ細かいが使うとは思えん。
面倒だな・・・

一応デフォルトでは・・・


MariaDB [horserace]> SHOW create database horserace;

                                                                                                                                                                  • +
Database Create Database
                                                                                                                                                                  • +
horserace CREATE DATABASE `horserace` /*!40100 DEFAULT CHARACTER SET sjis */
                                                                                                                                                                  • +

1 row in set (0.00 sec)

というように無言の設定があるようだが。

DB自体の設定は・・・


MariaDB [horserace]> \s

                          • -

mysql.exe Ver 15.1 Distrib 10.1.19-MariaDB, for Win32 (AMD64)

Connection id: 7
Current database: horserace
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server: MariaDB
Server version: 10.1.19-MariaDB mariadb.org binary distribution
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: sjis
Client characterset: cp932
Conn. characterset: cp932
TCP port: 3306
Uptime: 2 hours 1 min 57 sec

Threads: 1 Questions: 53 Slow queries: 0 Opens: 22 Flush tables: 1 Open tab
les: 16 Queries per second avg: 0.007

                          • -

接続に関しては・・・


MariaDB [horserace]> select user,host from mysql.user;

                                          • +
user host
                                          • +
root 127.0.0.1
root 192.168.3.3
root 192.168.3.4
root ::1
localhost
pma localhost
root localhost
www localhost
                                          • +

8 rows in set (4.72 sec)

で見れる。
IPv6でも設定できるみたい。

Linuxでは一発目の起動ができくて困ったが、ユーザ指定してないからで -u root でもできないので、多分普通にrootになってmysqlを立ち上げて、専用ユーザを作らなくてはならないみたい。


# mysql


mysql> CREATE USER www IDENTIFIED BY 'xxxx';
Query OK, 0 rows affected (0.06 sec)

$ mysql -u www
が可能になる。
あとはアクセス制限などを付けて準備完了。

[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

MySQL徹底入門第3版 5.5新機能対応 [ 日本MySQLユーザー会 ]
価格:3758円(税込、送料無料) (2018/9/21時点)


php,mysql windows -> linux 移行に関するメモ

Windowsphp,mysql使って居たのだけど linux の方が圧倒的に便利なので、いい加減嫌になって移行したのでメモ。

windows側のmysqlサーバの設定を、linux側からアクセス可能に変更。


> D:\***\XAMPP\mysql\bin\mysql.exe -u root
MariaDB [(none)]> use mysql;
MariaDB [(none)]> grant all privileges on my_database.* to root@"192.168.x.x" identified by 'passwd' with grant option;
(※ipのところは実際のlinuxのip。passws は実際のパスワード)

linux側でダンプしてリストア。


$ mysqldump -h 192.168.x.x -u root --default-character-set=sjis -p dbname > dump.sql
(※ipはwindows側のip。dbname はDB名)
そういえば sjisで入れてた。
なんか文字列データ中に \(バックスラッシュ)が入ってる??ので、viで修正。(良くないけど、とりあえず)

$ mysql -u www -p dbname < dump.sql

phpも7だったので、5にダウングレードする。


# apt remove php7.1
他にもリムーブしたかも

# apt-cache search php | grep "^php"
で出てきたもののうちphp7っぽいものを削除する。
# apt remove php7.1-cli とか?

https://freefielder.jp/blog/2016/04/ubuntu-1604-php5-installation.html
を参考に以下を実行。


# add-apt-repository ppa:ondrej/php
# apt-get update
php5をインストール

# apt install php5.6 php5.6-dev
devを入れないとpearが使えない。
https://lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu


[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

MySQL徹底入門第3版 5.5新機能対応 [ 日本MySQLユーザー会 ]
価格:3758円(税込、送料無料) (2018/9/21時点)


VMware

20年くらい前からVMwareユーザなのだが、あれよあれよという間にすごくいろんな環境に対応するものが出ている。
それはともあれ、VMware Playerの挙動があまりにも遅かったので、改善。

サスペンド、シャットダウンに10分近く待たされてたのが改善しました。

https://freesoft.tvbok.com/freesoft/virtual/vmware_tuning.html


HDDふっとんだ?

去年買ったばかりのWDのHDDが死にかけ・・・
仕方がないので、懲りずにまたWDのBLUEをポチる。
フォーマットして(MBR以外にGTPってのができてたのか)、1日かけて旧HDDから新HDDにコピーして(欠損ファイルがかなりある)