==MySQL==
[[Database][CentOS]]
{{amazon|4798124230}}
*Django インストール 1.5.1
# rpm -ivh MySQL-client-5.6.13-1.linux_glibc2.5.i386.rpm
<<blockquote>>serverインストール時に、初期パスワードの情報がコンソールに出力される<</blockquote>>
A random root password has been set. You will find it in '/root/.mysql_secret'.
<<blockquote>>もしくはログに出力されている<</blockquote>>
/var/log/mysqld.log | grep "temporary password"
$ sudo /etc/init.d/mysql restart
=====mysqld_safe(mysqld のラッパ)=====
shell> > cd mysql_installation_directory shell> > bin/mysqld_safe &
====起動設定がされたか確認====
# chkconfig | grep "mysql"
# mysql -u root mysql
=====新しいパスワードの設定=====
mysql> > update user set Password=PASSWORD('newpassword') -> > where User='root';
Query OK, 4 rows affected (0.11 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> > flush privileges;
Query OK, 0 rows affected (0.01 sec)
=====rootパスワードの変更=====
mysql> > set password for 'root'@'localhost' = password('newpassword');
Query OK, 0 rows affected (0.00 sec)
=====パスワードの設定 MySQL8=====
*https://qiita.com/arm_band/items/12208908041a5506d7f4
mysql> > set password for 'wordpress'@'localhost' = 'your password';
====初期の権限変更ツール mysql_secure_installation====
*初期パスワード /var/log/mysqld.log | grep "temporary password"
===簡易設定===
====バージョンの確認====
mysql> > select version();
+-----------+
| version() |
===作成===
# mysql -u root -p
mysql> > create database test_db default character set utf8;
Query OK, 1 row affected (0.00 sec)
*https://yoku0825.blogspot.com/2017/04/mysql-801utf8mb4ja0900ascs.html
===確認===
mysql> > show create database test_db;
+----------+------------------------------------------------------------------+
| Database | Create Database |
|}
===ユーザーの作成===
mysql> > create user test_user@localhost;
Query OK, 0 rows affected (0.03 sec)
===権限の付与===
=====限定して付与=====
mysql> > grant create,alter,select,insert,update,delete,index on *.* to test_user@localhost identified by 'newpassword';
Query OK, 0 rows affected (0.00 sec)
=====管理権限を付与=====
*test_admin@localhost を作成した上で管理権限を付与
*リモートアクセスを可能とするには、test_admin@localhost の部分を test_admin@'%' とする
mysql> > grant all privileges on *.* to test_admin@localhost identified by 'newpassword' with grant option;
Query OK, 0 rows affected (0.00 sec)
====root@%を追加====
=====確認=====
mysql> > select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
=====ユーザーの追加=====
mysql> > create user 'root'@'%' identified by 'パスワード'; mysql> > set password for 'root'@'%' = 'パスワード'; mysql> > grant all on *.* to 'root'@'%';
=====確認 =====
mysql> > select user, host from user;
+------------------+-----------+
| user | host |
===例===
====バックアップ例====
# mysqldump --default-character-set=utf8 -uroot -p mt > > mt_backup20140120.sql
Enter password:
====レストア例====
*mysqldumpの出力はSQL文の羅列であるため、復元するにはリダイレクトを使ってmysqlに結果を与えれば良い
# mysql -u root -p mt < < mt_backup20140120.sql
==Tips==
===管理===
====テーブル一覧を表示====
# mysql -u root -p
mysql> > use mt
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> > show tables;
+-------------------+
| Tables_in_mt |
====制約を無視してテーブルをtruncateする====
*一旦、FOREIGN_KEY_CHECKSを0にする
mysql> > SET FOREIGN_KEY_CHECKS=0; mysql> > truncate table hoge; mysql> > SET FOREIGN_KEY_CHECKS=1;
===mysqlコマンド===
====ソースファイルのSQLを実行====
\.<<ファイル名>>
====データベースの変更====
use
show tables
====ポートを調べる====
mysql> > show variables like 'port';
+---------------+-------+
| Variable_name | Value |