mysql新添加用戶與刪除用戶具體操作命令
方法1 :使用mysql root(root權限)用戶登陸直接賦權也可以創建用戶
/usr/bin/mysqladmin -u root password 123456
mysql -uroot -p
密碼
查看所有用戶名與密碼
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;;
更改數據庫密碼
user mysql
修改mysql數據庫的密碼
UPDATE user SET Password=PASSWORD('123456') where USER='root';
mysql root密碼為空 登陸的時候不需要密碼
UPDATE user SET Password=PASSWORD(null) where USER='root';
flush privileges;
方法二:
1.新建用戶。
//登錄MYSQL
@>mysql -u root -p
@>密碼
//首先為用戶創建一個數據庫(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 密碼為:1234 的用戶。
然後登錄一下。
mysql>exit;
@>mysql -u phplamp -p
@>輸入密碼
mysql>登錄成功
2.為用戶授權。
格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by "密碼";
>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
@>密碼
mysql>DELETE FROM user WHERE User="test" and Host="localhost";
mysql>flush privileges;
//刪除用戶的數據庫
mysql>drop database testDB;
4.修改指定用戶密碼。
@>mysql -u root -p
@>密碼
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 用戶名@'%';
>drop user 用戶名@ localhost;