方法1 :使用mysql root(root權(quán)限)用戶登陸直接賦權(quán)也能夠創(chuàng)建用戶
/usr/bin/mysqladmin -u root password 123456
mysql -uroot -p
password
查看全部username與password
select host ,user ,password from user;
grant all on ec.* to 'root'@'%'? identified by '123456';
grant all privileges on ec.* to 'cockpit'@'%'? identified by '123456';
grant all on ec.* to 'cockpit'@'%'? identified by '123456';
grant all privileges on ec.* to 'cockpit'@'%'? identified by '123456';
flush privileges;;
更改數(shù)據(jù)庫password
user mysql
改動mysql數(shù)據(jù)庫的password
?UPDATE user SET Password=PASSWORD('123456') where USER='root';
mysql? rootpassword為空? 登陸的時候不須要password
UPDATE user SET Password=PASSWORD(null) where USER='root';
flush privileges;
方法二:
1.新建用戶。
//登錄MYSQL
@>mysql -u root -p
@>password
//首先為用戶創(chuàng)建一個數(shù)據(jù)庫(testDB)
mysql>create database testDB? default character set utf8;;
//創(chuàng)建用戶
mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
//刷新系統(tǒng)權(quán)限表
mysql>flush privileges;
這樣就創(chuàng)建了一個名為:test? password為:1234? 的用戶。
然后登錄一下。
mysql>exit;
@>mysql -u phplamp -p
@>輸入password
mysql>登錄成功
2.為用戶授權(quán)。
??? 格式:grant 權(quán)限 on 數(shù)據(jù)庫.* to username@登錄主機 identified by "password";
??? >grant all privileges on phplampDB.* to phplamp@localhost identified by '1234";
??? 授權(quán)test用戶擁有全部數(shù)據(jù)庫的某些權(quán)限:
mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
???? //test用戶對全部數(shù)據(jù)庫都有select,delete,update,create,drop 權(quán)限。
//@"%" 表示對全部非本地主機授權(quán)。不包含localhost。(localhost地址設(shè)為127.0.0.1。假設(shè)設(shè)為真實的本地地址,不知道能否夠,沒有驗證。)
3.刪除用戶。
@>mysql -u root -p
@>password
mysql>DELETE FROM user WHERE User="test" and Host="localhost";
mysql>flush privileges;
//刪除用戶的數(shù)據(jù)庫
mysql>drop database testDB;
4.改動指定用戶password。
@>mysql -u root -p
@>password
mysql>update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
mysql>flush privileges;
delete from? user where User="test" and Host="localhost";
也能夠試試:
刪除賬戶及權(quán)限:>drop user username@'%';
>drop user username@ localhost;