LoginSignup
3

More than 5 years have passed since last update.

mysql基本コマンド

Last updated at Posted at 2016-02-25

mysqlにログイン

$ mysql -u root -p

-uでユーザーを指定。
ここではroot

-pでパスワードを要求

データベースを確認

mysql>show databases;

データベースを選択

mysql> use db_name;

mysqlパスワードを設定

mysql>set password for root@localhost = password("passwd");

ユーザーを作成し、ユーザーに権限をふる

mysql>grant all on test_app.* to user@localhost identified by "passwd";

mysqlの起動の確認

$ sudo mysqladmin ping
実行結果が
mysqld is aliveと出ればOK

権限を確認

mysql> select Host,User from mysql.user;

mysql起動

$ sudo system start mysqld.service

起動時の設定を確認

$ sudo systemctl list-nit-files | grep mysql

mysql.service enabled
mysql.service enabled

これならOK

ダンプファイルを取り込む

$ mysql -u app_user -p test_app < app.sql

バックアップするとき

$ mysqldump -u app_user -p dbname > dbnanme.sql

mysqlインストール(Centos)

$ sudo yum install -y mysql-server mysql-devel

mysql-develは RailsでMySQLを使うために必要なgemを使うために必要なパッケージ。

mysql-serverはmysql

mysqlの状態を表示

mysql>\s
```
mysql Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using EditLine wrapper

Connection id: 23
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.27 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 6 days 4 hours 2 min 11 sec

Threads: 1 Questions: 2198 Slow queries: 0 Opens: 112 Flush tables: 1 Open tables: 75 Queries per second avg: 0.004

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3