MySql 操作

1 、 查看用戶:
    select host,user,password from mysql.user;

2、 添加用戶: 
    create user 用戶名 identified by '密碼';
     
   create user coc identified by 'root';

3、 創建數據庫
   create database coc_test1;


4、 如何給用戶分配權限
    
①、grant 權限 on 數據庫.數據表 to '用戶' @ '主機名';

   grant all on *.* to 'coc'@'%';
   這個時候 coc就擁有了 所有權限了

  grant all privileges on coc_test1.* to coc@'%' identified by 'root';
  
  grant select,insert,update,delete,create,drop on coc_test1.*  to coc@'%' identified by 'root';

  grant all privileges on *.* to coc@'%' identified by 'root';


②、 如何更精準的控制用戶的權限呢?
    grant 權限 on 數據庫.數據表 to '用戶' @ '主機名';


5. 如何收回 權限,一般指有root用戶才具有該權限

① revoke 權限 on  數據庫.數據表 from '用戶'@'主機名';

   revoke select,insert,update on coc_test1.* from root1@'%';


####
第一步:mysql服務的啓動和停止

net stop mysql

net start mysql

第二步:直接登陸mysql

語法如下: mysql -u用戶名 -p用戶密碼

鍵入命令mysql -uroot -p, 回車後提示你輸入密碼,輸入123456,然後回車即可進入到mysql中了,mysql的提示符是:

mysql>

注意,如果是連接到另外的機器上,則需要加入一個參數-h機器IP

 //對localhost授權:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。

3、刪除用戶

   @>mysql -u root -p

  @>密碼

   mysql>Delete FROM user Where User='test' and Host='localhost';

   mysql>flush privileges;

   mysql>drop database testDB; //刪除用戶的數據庫

刪除賬戶及權限:>drop user 用戶名@'%';

        >drop user 用戶名@ localhost; 

 

4. 修改指定用戶密碼

    @>mysql -u root -p

    @>密碼

    mysql>update mysql.user set password=password('新密碼') where User="test" and Host="localhost";

    mysql>flush privileges;

 

5. 列出所有數據庫

  mysql>show database;

 

6. 切換數據庫

  mysql>use '數據庫名';

 

7. 列出所有表

  mysql>show tables;

 

8. 顯示數據表結構

  mysql>describe 表名;

 

9. 刪除數據庫和數據表

  mysql>drop database 數據庫名;

  mysql>drop table 數據表名;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章