| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

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

案内メニュー