【原創】數據庫基礎之Mysql(1)經常使用命令

1 建立用戶

CREATE USER 'username'@'host' IDENTIFIED BY 'password';mysql

好比sql

create user 'test_user'@'%' identified by 'test';ide

ps:若是隻容許本機登陸則host=localhost,若是容許從任意遠程主機登錄則host=%ssl

修改密碼table

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');test

2 受權

GRANT privileges ON dbname.tablename TO 'username'@'host'登錄

好比權限

GRANT ALL ON test_db.* TO 'test_user'@'%';密碼

撤銷權限數據

REVOKE privilege ON dbname.tablename FROM 'username'@'host';

3 查看某個用戶的受權

show grants for test_user;

4 數據導出

$ mysqldump -u dbuser -p dbname [tablename1] [tablename2] > dump.sql

ps:tablename可選

若是想導出全部database,dataname處傳 --all-databases

5 數據導入

mysql>source /path/dump.sql

或者

$ mysql -uusername -p dbname < dump.sql

6 定位問題

mysql>show processlist;

mysql>show variables;

7 修改字符集

mysql> alter database $database_name character set utf8;mysql> alter table $table_name default character set utf8;mysql> alter table $table_name change $column_name $column_name varchar(50) character utf8;

相關文章
相關標籤/搜索