[mysql]基本構文実行
- CREATE TABLE
mysql> create table HCDR.bureau_balance ( AA integer, BB numeric(5,0), CC varchar(3)); Query OK, 0 rows affected (0.07 sec)
- DROP TABLE
mysql> DROP TABLE HCDR.bureau_balance; Query OK, 0 rows affected (0.05 sec)
- LOAD DATA
mysql> LOAD DATA INFILE '/Users/XXXX/bureau_balance.csv' INTO TABLE HCDR.bureau_balance; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ureau_balance' at line 1
うーん、エラーが出ました
mysql> SELECT @@global.secure_file_priv; +---------------------------+ | @@global.secure_file_priv | +---------------------------+ | NULL | +---------------------------+ 1 row in set (0.00 sec)
/etc/my.cnfを作り、空の設定に
$ sudo vi /etc/my.cnf [mysqld] secure-file-priv = ""
sqlサーバを再起動し、確認をすると、空になったことがわかる
$ mysql.server restart Shutting down MySQL .. SUCCESS! Starting MySQL .. SUCCESS! $ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.11 Homebrew Copyright (c) 2000, 2018, 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> SELECT @@global.secure_file_priv; +---------------------------+ | @@global.secure_file_priv | +---------------------------+ | | +---------------------------+ 1 row in set (0.00 sec)
まだエラーが出てる。。。
mysql> LOAD DATA INFILE '/Users/XXXX/bureau_balance.csv' INTO TABLE HCDR.bureau_balance IGNORE 1 LINES; ERROR 1265 (01000): Data truncated for column 'AA' at row 1
区切り文字がデフォルトだと、commaになってなかったので、エラーが出ていた。なので、下記の形でTERMINATED BY を使って区切り文字を指定してあげる
LOAD DATA INFILE '/Users/XXXX/bureau_balance.csv' INTO TABLE HCDR.b ureau_balance FIELDS TERMINATED BY ',' IGNORE 1 LINES;
- SHELLから実行
mysql -uroot -p HCDR < create_bureau_balance.sql
DROP TABLE HCDR.bureau_balance; -- などのsqlを記入
install mysql for mac
お家でデータ分析して遊ぼうと思ったけど、普段の仕事でsqlしか使ってなさすぎて、家で何かするのにもデータベース欲しくなったので、mysqlをmacにインストールすることにした
$ brew update $ brew upgrade $ brew update Already up-to-date. $ brew install mysql ==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.11.high_sierra.bo ######################################################################## 100.0% ==> Pouring mysql-8.0.11.high_sierra.bottle.tar.gz ==> /usr/local/Cellar/mysql/8.0.11/bin/mysqld --initialize-insecure --user=crazy ==> Caveats 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 have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start ==> Summary 🍺 /usr/local/Cellar/mysql/8.0.11: 254 files, 232.6MB
$ brew info mysql mysql: stable 8.0.11 (bottled) Open source relational database management system https://dev.mysql.com/doc/refman/8.0/en/ Conflicts with: mariadb (because mysql, mariadb, and percona install the same binaries.) mariadb-connector-c (because both install plugins) mysql-cluster (because mysql, mariadb, and percona install the same binaries.) mysql-connector-c (because both install MySQL client libraries) percona-server (because mysql, mariadb, and percona install the same binaries.) /usr/local/Cellar/mysql/8.0.11 (254 files, 232.6MB) * Poured from bottle on 2018-07-13 at 22:57:55 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb ==> Dependencies Build: cmake ✘ Required: openssl ✔ ==> Requirements Required: macOS >= 10.10 ✔ ==> Options --with-debug Build with debug support --with-embedded Build the embedded server --with-local-infile Build with local infile loading support --with-memcached Build with InnoDB Memcached plugin --with-test Build with unit tests ==> Caveats 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 have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start $ mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) $ mysql.server start Starting MySQL . SUCCESS!
$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.11 Homebrew Copyright (c) 2000, 2018, 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> set password for root@localhost=password('hogehoge'); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password('hogehoge')' at line 1
mysqlへ、ログインできた。とりあえずexitする
mysql> exit Bye
ここから、パスワードを設定する
$ set password for root@localhost=password('hogehoge'); -bash: syntax error near unexpected token `('
頭を空っぽにしてググったらできるって思ったコマンド投げたら怒られた。。。
$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.11 Homebrew Copyright (c) 2000, 2018, 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> set password for root@localhost=password('hogehoge'); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password('hogehoge')' at line 1 mysql> set password for root@localhost=password('hogehoge') -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password('hogehoge')' at line 1 mysql> exit Bye
当然ダメだったけど、一応mysqlにログインしてからもやってみた。
MySQL5.7の初期設定まとめこちらの記事を参考に
$ mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN 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 plugin? 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) : 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!
まず、パスワードを入力 他はとりあえず全部YでOK
$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.11 Homebrew Copyright (c) 2000, 2018, 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> create database HCDR; Query OK, 1 row affected (0.02 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | HCDR | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.01 sec) mysql> drop database HCDR; Query OK, 0 rows affected (0.02 sec) mysql> use HCDR ERROR 1049 (42000): Unknown database 'hcdr' mysql> create database HCDR; Query OK, 1 row affected (0.09 sec) mysql> use HCDR Database changed
install chainer for mac
新しいmaxで、何も考えずにpython久しぶりに使おうと思ったらpythonすらinstall してなかったので、、、
homebrew 経由にてinstallした
python からね
・
・
・
なので、まずpythonがinstall されているか確認
$ which python3
/usr/local/bin/python3
入ってた python3がいいらしいの
$which pip3
/usr/local/bin/pip3
pip3も入っているか確認 pythonのversion も確認
$ python3 --version
Python 3.6.1
3以上ならOK
じゃあインストールするよー chainer と見せかけてpythonで機械学習するのに必要なの(ほんの一部)もついでに入れる
$ pip3 install numpy # 線形代数
$ pip3 install scipy # 数式処理
$ pip3 install matplotlib # 描画
$ pip3 install pandas # データ操作
$ pip3 install scikit-learn
$ pip3 install chainer
$ pip3 install jupyter
ホームページ制作したよ
自称データサイエンティストがブログをはじめた
初めてのブログは、知り合いのホームページを作製する話。(早速データサイエンス関係ない!)
早速本題へ。
聞いたところ、既存のホームページ作製サイトじゃ満足できなさそうだったので、、、、仕方なくレンタルサーバを借りてホームページを一から作ることになりました。
レンタルサーバの機能に必須なのが、1日に一回cronを流さなければならないということ。
ということで、レンタルサーバについてちょっと調べてみた。
以下のサイトを参考にさせていただきました。(ありがとうございますmm)
Cronが使えるレンタルーサーバーTOP
レンタルーサーバー選びで失敗しないための情報源
¥1000/月 のものは、
サーバ名 | プラン名 | 金額 | HD容量 | メール数 | ドメイン数 | 使用可能言語 | cronについて | 初期費用 |
---|---|---|---|---|---|---|---|---|
さくら | スタンダード | ¥417 | 10GB | 無制限 | マルチドメイン:20,サブドメイン:20,comドメイン取得:1800円 | オリジナルCGI,MySQL,アクセス制限,アクセス解析,MovableType,SSL | 有料オプション(5個まで?) | 1000 |
ロリポップ | エコノミー | ¥100~ | 10GB | 410個 | マルチドメイン:20 | SQLite,baserCMS,PHP(CGI版),Perl,Ruby,Python,WebDAV,アクセス解析 | 標準装備(1個:5分間隔) | ¥1500 |
ロリポップ | ライト | ¥250~ | 50GB | マルチドメイン:50 | MySQL5(1),SQLite,WordPress,EC-CUBE,baserCMS,SSL,PHP(CGI版),Perl,Ruby,Python,WebDAV,アクセス解析 | 標準装備(5個:5分間隔) | ¥1500 | |
ロリポップ | スタンダード | ¥500~ | 120GB | マルチドメイン:100 | MySQL5(30),SQLite,WordPress,EC-CUBE,baserCMS,SSL,PHP(CGI版),Perl,Ruby,Python,SSH,WebDAV,アクセス解析 | 標準装備(10個:1分間隔) | ¥1500 | |
ハッスルサーバー | なし | ¥166.7~ | 3GB | 不明 | 32 | CGI,Perl,Ruby,Python,PHP,SSI,アクセス解析,.htaccess,FTP,MySQL | ¥1000 | |
XREA+ | ¥190.5~ | 10GB | マルチドメイン:10,サブドメイン:20 | SSL,POP,SMTP,IMAP,APOP,FTP,アクセス解析,CGI/SSI,Perl,PHP,Ruby,SQLite2/3,Python,C/C++,.htaccess,SSH | 標準装備 | 無料 | ||
CORE SERVER | MINI | ¥198~ | 60GB | 200 | マルチ/サブドメイン合計:50 | POP,SMTP,IMAP,APOP,CGI/SSI,Perl,PHP,Ruby,SQLite,SSH,Python,C/C++,.htaccess, | 標準装備 | 無料 |
CORE SERVER | A | ¥397~ | 120GB | 無制限 | マルチ/サブドメイン:無制限 | 標準装備 | 無料 | |
CORE SERVER | B | ¥785~ | 240GB | 無制限 | マルチ/サブドメイン:無制限 | 標準装備 | 無料 | |
クイッカ | エントリー | ¥98 | 10GB | 5 | サブドメイン:10 | PHP,アクセス制限,アクセス解析,オリジナルCGIメール関係,SSL,MovableType | 有料オプション | ¥980 |
クイッカ | ライト | ¥250 | 10GB | 10 | マルチドメイン:50,サブドメイン:50 | PHP,アクセス制限,アクセス解析,オリジナルCGIメール関係,SSL,MySQL(5),MovableType,XOOPS | 有料オプション | 1000 |
クイッカ | スタンダード | ¥490 | 30GB | 30 | マルチドメイン:200,サブドメイン:200 | PHP,アクセス制限,アクセス解析,オリジナルCGIメール関係,SSL,MySQL(20),MovableType,XOOPS | 有料オプション | 1000 |
クイッカ | プレミアム | ¥980 | 40GB | 無制限 | マルチドメイン:500,サブドメイン:500 | PHP,アクセス制限,アクセス解析,オリジナルCGIメール関係,SSL,MySQL(無制限),PostgreSQL(無制限),MovableType,XOOPS | 標準装備 | 2000 |
ServerMan@VPS | Entryプラン | ¥490 | 10GB | 無制限 | マルチドメイン:標準装備,サブドメイン:標準装備,comドメイン取得:1800円 | オリジナルCGI,SSL,MovableType | 標準装備 | 0 |
ServerMan@VPS | Standardプラン | ¥980 | 10GB | 無制限 | マルチドメイン:標準装備,サブドメイン:標準装備,comドメイン取得:1800円 | オリジナルCGI,PHP,MySQL,アクセス解析,SSL,MovableType | 標準装備 |
*1:ホームページ制作者のくせにテーブルがはみ出てしまう失態orz だれかはてぶで設定する方法教えてください... overflowでもtable-layoutでも設定できないとか聞いてない
*2:結局レンタルサーバーは、さくらインターネットにしました