mysqlデータベースの作成、ユーザーの追加、ユーザー権限の追加

1533 ワード

一、mysqlデータベースの作成
1.データベース構文の作成
--     “testdb”   ,       utf8
CREATE DATABASE IF NOT EXISTS testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

二、ユーザーの作成
1.新規ユーザー
 --       :test    :1234    
 create user 'test'@'localhost' identified by '1234';

注意:ここで「localhost」とは、そのユーザーがローカルでしかログインできず、別のマシンでリモートでログインできないことを意味します.リモートでログインしたい場合は、「localhost」を「%」に変更し、どのパソコンでもログインできることを示します.リモートでログインできるマシンを指定することもできます.
2.ユーザーの照会
--    
select user,host from mysql.user;

3.ユーザーの削除
--    “test”
drop user test@localhost ;
--              ,      
drop user test@'%';

4.パスワードの変更
--  1,      ;    “test”    “1122”
set password for test =password('1122');
--  2,    ;    “test”    “1234”
update  mysql.user set  password=password('1234')  where user='test'
--  
flush privileges;

5.ユーザー割当権限
--    test    IP    “testdb”     
grant all privileges on 'testdb'.* to 'test'@'%' identified by '1234';  

--    
flush privileges; 

--    “test”    IP      “testdb”     、  、    ,            
grant create,alter,drop,select,insert,update,delete on testdb.* to test@'%';     

6.ユーザー権限の表示
--    “test”
show grants for test;

注意:権限を変更した後、必ずサービスをリフレッシュするか、サービスを再起動し、サービスをリフレッシュします:flush privileges;
転載先:https://www.cnblogs.com/wuyunblog/p/9109269.html