一些主要的命令:
登錄:
mysql -u username -p
顯示全部的數據庫:
show databases;
使用某一個數據庫:
use databasename;
顯示一個數據庫的全部表:
show tables;
退出:
quit;
刪除數據庫和數據表
mysql>drop database 數據庫名;
mysql>drop table 數據表名;
用戶相關:
查看全部的用戶:
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
新建用戶:
CREATE USER
'dog'
@
'localhost'
IDENTIFIED BY
'123456'
;
為用戶授權:
格式:
grant 權限 on 數據庫.* to username@登錄主機 identified by "password";
演示樣例:
grant all privileges on testDB.* to test@localhost identified by '1234';
然后須要運行刷新權限的命令:
flush privileges;
為用戶授予部分權限:
grant select,update on testDB.* to test@localhost identified by '1234';
授予一個用戶全部數據庫的某些權限:
grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
刪除用戶:
Delete FROM user Where User='test' and Host='localhost';
然后刷新權限;
刪除賬戶及權限:>drop user username@'%';
>drop user username@ localhost;
>drop user username@ localhost;
改動指定用戶password
使用root登錄:
mysql -u root -p
運行命令:
update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
刷新權限:
flush privileges;
使用root登錄:
mysql -u root -p
運行命令:
update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
刷新權限:
flush privileges;
