//登錄MYSQL
@>mysql -u root -p
@>密碼
//創建用戶
mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("123456"));
//刷新系統權限表
mysql>flush privileges;
這樣就創建了一個名爲:test 密碼爲:123456 的用戶。
然後登錄一下。
mysql>exit;
@>mysql -u test -p
@>輸入密碼
mysql>登錄成功
2.爲用戶授權:
//登錄MYSQL(有ROOT權限)。我裏我以ROOT身份登錄.
@>mysql -u root -p
@>密碼
//首先爲用戶創建一個數據庫(test)指定字符集
mysql>create database test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
//授權phplamp用戶擁有phplamp數據庫的所有權限。
>grant all privileges on test.* to test;
//刷新系統權限表
mysql>flush privileges;
mysql>其它操作
/*
如果想指定部分權限給一用戶,可以這樣來寫:
mysql>grant select,update on test.* to test;
//刷新系統權限表。
mysql>flush privileges;
*/
3.刪除用戶:
@>mysql -u root -p
@>密碼
mysql>DELETE FROM user WHERE User="test" and Host="localhost";
mysql>flush privileges;
//刪除用戶的數據庫
mysql>drop database test;
4.修改指定用戶密碼:
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
mysql>flush privileges;
5.設置數據庫忽略大小寫:
[root@localhost ~]# cat /etc/my.cnf
在[mysqld]後添加添加lower_case_table_names=1(1是不區分大小寫,0是區分)
6.查看數據庫的字符集:
mysql> show variables like '%char%';
7.設置數據庫的字符集:
[root@localhost ~]# vi /etc/my.cnf
在[mysqld]最後加上default-character-set=utf8
在[client]的最後加上default-character-set=utf8
重啓服務器
8.重啓數據庫服務:
[root@localhost ~]# /etc/init.d/mysqld start(啓動mysql服務)
[root@localhost ~]# /etc/init.d/mysqld stop(關閉mysql服務)
[root@localhost ~]# /etc/init.d/mysqld restart(重啓mysql服務)
參考自:http://www.cnblogs.com/analyzer/articles/1045072.html