まず、アクセスするぜ🚶♀️
■1. rootのパスワードを知る。(2通り)
cat /var/log/mysqld.log | grep password
A temporary password is generated for root@localhost: ??????????
sudo cat /var/log/mysqld.log | grep "temporary password"
A temporary password is generated for root@localhost: ??????????
■2.mysqに入る (2通り)
mysql -u root -p
mysql-ctl start
■3.rootのパスワード設定。
「-------」はパスワードを設定しよう。
(大文字・小文字・数字・特殊記号はそれぞれ最低1つは入れる。)
set password for root@localhost=password('-----------------');
Query OK, 0 rows affected, 1 warning (0.00 sec)
表示👁
■データベースの情報確認コマンド
show databases;
■テーブルの情報確認コマンド
show tables from データベース名;
■カラム(項目)の情報確認コマンド
show columns from テーブル名 from データベース名;
show create table テーブル名;
desc テーブル名;
select * from テーブル名;
追加➕
■データベース追加
create database データベース名;
文字コード指定(utf8とか)
create database データベース名 default character set 文字コード;
■テーブル追加
1.
use データベース名;
2.(オプションはなくてもいい。)
create table テーブル名
(
カラム名 データ型 オプション,
カラム名 データ型 オプション,
カラム名 データ型 オプション,
カラム名 データ型 オプション
);
2.(example)
create table test
(
id integer,
name char(16),
username char(20) not null,
sub_name text
);
2.(文字コードをutf8に指定)
create table テーブル名
(
カラム名 データ型 オプション,
カラム名 データ型 オプション,
カラム名 データ型 オプション,
カラム名 データ型 オプション
); DEFAULT CHARSET=utf8;
削除🗑
■データベースを削除
drop database データベース名;
■テーブルを削除
drop table テーブル名;
ユーザー権限🙋♂️
■MySQLのユーザーを見る
SELECT User, Host FROM mysql.user;
■ユーザーを追加する
CREATE USER 'ユーザ名@'ホスト名' IDENTIFIED BY 'パスワード';
■特定ユーザーの権限確認
show grants for ユーザー名@ホスト名;
■あるユーザーのselect、update、insertを許可する。
selectと、updateのみ
grant select, update on データベース名 to ユーザー名@ホスト名 identified by 'パスワード';
selectと、insertのみ
grant select, insert on データベース名 to ユーザー名@ホスト名 identified by 'パスワード';
■権限変更を反映する。
FLUSH PRIVILEGES;
システム🤖
■MySQLの細かい状態(バージョン、ログインユーザー、文字コードなど色々)
status
■MySQL再起動
sudo service mysqld start
■細かい設定の書き換え
sudo vim /etc/my.cnf