MySQL.md
... ...
@@ -1,6 +1,9 @@
1 1
[[_TOC_]]
2 2
3 3
# リンク
4
+- [MariaDB](https://mariadb.com/)
5
+ - [MariaDB Package Repository Setup and Usage - MariaDB Knowledge Base](https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/)
6
+
4 7
- [MySQL AB](http://www-jp.mysql.com/)
5 8
- [MySQL 5.7 Reference Manual](http://dev.mysql.com/doc/refman/5.7/en/)
6 9
- [7.3.6 Password Expiration Policy](http://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html)<br />
... ...
@@ -24,12 +27,42 @@ BMP 外の文字(絵文字等)を格納するには character-set = utf8mb4 を
24 27
- [[Perl/DBIx-Custom]]
25 28
26 29
# インストール
30
+## MariaDB
31
+```
32
+# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
33
+# dnf install -y MariaDB-server mariadb-devel
34
+```
35
+## MySQL
27 36
```
28
-# yum -y install mysql-server
37
+# yum -y install mysql-server mysql-devel
29 38
```
30 39
31 40
# 初期設定
32
-/etc/my.cnf に追加
41
+## MariaDB
42
+- /etc/my.cnf.d/mysql-clients.cnf (抜粋)
43
+```
44
+[mysql]
45
+default-character-set = utf8mb4
46
+
47
+[mysqladmin]
48
+default-character-set = utf8mb4
49
+
50
+[mysqldump]
51
+default-character-set = utf8mb4
52
+```
53
+- /etc/my.cnf.d/server.cnf (抜粋)
54
+```
55
+[server]
56
+character-set-server = utf8mb4
57
+
58
+[mysqld]
59
+character-set-server = utf8mb4
60
+
61
+[mariadb]
62
+character-set-server = utf8mb4
63
+```
64
+## MySQL
65
+- /etc/my.cnf (抜粋)
33 66
```
34 67
[mysqld]
35 68
default-character-set = utf8
... ...
@@ -48,18 +81,21 @@ default-character-set = utf8
48 81
default-character-set = utf8
49 82
```
50 83
51
-MySQL起動
84
+# MySQL起動
85
+## CentOS7,8
52 86
```
53
-# service mysqld start
87
+# systemctl start mysqld
88
+# systemctl enable mysqld
89
+# systemctl status mysqld
54 90
```
55
-
56
-mysqld自動起動設定
91
+## CentOS6
57 92
```
93
+# service mysqld start
58 94
# chkconfig mysqld on
59 95
# chkconfig --list mysqld
60 96
```
61 97
62
-セキュリティ初期設定
98
+# セキュリティ初期設定
63 99
```
64 100
# mysql_secure_installation
65 101
```
... ...
@@ -265,27 +301,41 @@ mysql> SOURCE バックアップファイル名.sql;
265 301
- 特定のデータベースについて、テーブル毎に個別にバックアップを行うスクリプト
266 302
267 303
- bash 版
268
-[dump.zip](dump.zip)
269 304
```bash
270 305
#!/bin/bash
271
-UserName=testuser
272
-DataBase=testdb
273
-WorkFile=tables.txt
274 306
275
-echo enter database password:
276
-read PASSWORD
307
+if [ $# -lt 2 ]; then
308
+ cmd=`basename $0`
309
+ echo "usage: ${cmd} <DataBase> <UserName>"
310
+ exit 1
311
+fi
312
+
313
+DataBase=$1
314
+UserName=$2
315
+Dir=Tables
316
+
317
+if [ ! -d ${Dir} ]; then
318
+ mkdir ${Dir}
319
+fi
320
+
321
+WorkFile=${Dir}/_tables.txt
322
+
323
+echo "enter password for ${UserName}:"
324
+read Password
277 325
278
-mysql -u $UserName --password=$PASSWORD --database $DataBase -e "show tables;" > $WorkFile
326
+mysql -u "${UserName}" --password="${Password}" \
327
+ --database "${DataBase}" -e "show tables;" > "${WorkFile}"
279 328
280
-exec 3< $WorkFile
329
+exec 3< "${WorkFile}"
281 330
282 331
# drop header line
283
-read LINE 0<&3
332
+read Table 0<&3
284 333
285
-while read LINE 0<&3
334
+while read Table 0<&3
286 335
do
287
-echo ${LINE}
288
-mysqldump -u $UserName --password=$PASSWORD --force $DataBase ${LINE} > Tables/${LINE}.sql
336
+ echo "${Table}"
337
+ mysqldump -u "${UserName}" --password="${Password}" --force \
338
+ "${DataBase}" "${Table}" > "${Dir}/${Table}.sql"
289 339
done
290 340
291 341
exec 3<&-
... ...
@@ -501,4 +551,4 @@ DRIVER={MySQL ODBC x.xx Driver}; SERVER=サーバ名; DATABASE=データベー
501 551
- [松のページ](http://www.mmatsubara.com/)
502 552
- [A5:SQL Mk-2](http://a5m2.mmatsubara.com/) フリーの汎用SQL開発ツール/ER図ツール
503 553
504
-- 後で試す。
505 554
\ No newline at end of file
555
+- 後で試す。