/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;;
更改數據庫password
user mysql
改動mysql數據庫的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
//首先為用戶創建一個數據庫(testDB)
mysql>create database testDB default character set utf8;;
//創建用戶
mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
//刷新系統權限表
mysql>flush privileges;
這樣就創建了一個名為:test password為:1234 的用戶。
然后登錄一下。
mysql>exit;
@>mysql -u phplamp -p
@>輸入password
mysql>登錄成功
2.為用戶授權。
格式:grant 權限 on 數據庫.* to username@登錄主機 identified by "password";
>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234";
授權test用戶擁有全部數據庫的某些權限:
mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
//test用戶對全部數據庫都有select,delete,update,create,drop 權限。
//@"%" 表示對全部非本地主機授權。不包含localhost。(localhost地址設為127.0.0.1。假設設為真實的本地地址,不知道能否夠,沒有驗證。)
//對localhost授權:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';就可以。
3.刪除用戶。
@>mysql -u root -p
@>password
mysql>DELETE FROM user WHERE User="test" and Host="localhost";
mysql>flush privileges;
//刪除用戶的數據庫
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";
也能夠試試:
刪除賬戶及權限:>drop user username@'%';
>drop user username@ localhost;