建立:mysql
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'new_password
' PASSWORD EXPIRE;sql
受權:數據庫
Grant all on *.* to 'jeffrey'@'localhost';服務器
建立並受權ide
Grant all privileges on *.* to root1@'%' identified by "root" with grant option;命令行
建立用戶:
CREATE USER 'jacky'@'localhost' identified BY 'mypass';
GRANT SELECT ,UPDATE ON *.* TO 'testUser'@'localhost' identified BY 'testpwd';
INSERT INTO mysql.user(host,user,password) VALUES ('localhost','customer1',password('customer1'))
*identified with只能在MYSQL5.5.7及以上版本使用,identified with和identified by是互斥的
*CREATE USER語句的操做會被記錄到服務器日誌文件或者操做歷史文件中 cat ~/.mysql_history
*查出哈希值 SELECT password('mypass'); 再使用 CREATE user 'tom'@'localhost' identified BY password 'B292FED686394CC81F802198C941D43EF0E4FB62'; 再賦值日誌
賦予權限
grant all privileges on *.* to root@'(localhost或192.168.1.1或%)' identified by "password" with grant option;
flush privileges;
show grants;code
回收權限
revoke delete on *.* from 'root'@'localhost';
REVOKE INSERT ON *.* FROM 'grantUser'@'localhost';blog
INSERT, SELECT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE VIEW, SHOW VIEW, TRIGGERip
查看用戶
select host,user,password from user; 重命名:rename user 'jack'@'%' to 'jim'@'%';
刪除用戶
drop user 'root'@'localhost'; 或 DELETE FROM mysql.user WHERE `Host`='localhost' and `User`='testUser'
修改密碼
SET PASSWORD=PASSWORD("123456")
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
mysqladmin -uroot -p123456 password 1234abcd
update user set PASSWORD = PASSWORD('1234abcd') where user = 'root';
grant USAGE ON *testUser*TO 'localhost' identified BY '123456';
找回root密碼
mysqld_safe --skip-grant-tables user=mysql
/etc/init.d/mysql start-mysqld --skip-grant-tables
基礎查看操做
show databases; show tables; show columns from 表 ; desc 表; show create table 表
刪除整個表數據
truncate table 表名 或delete from 表名
*效率上truncate比delete快,但truncate刪除後不記錄mysql日誌,不能夠恢復數據。
刪除某條表數據
delete from ofUser where username='admin';
插入某條表數據
insert into ofUser (username,plainPassword,creationDate,modificationDate) values('admin','admin','1464292787204','1464292787204');
================================================================
命令行下具體用法以下:
mysqldump -u用戶名 -p密碼 -d 數據庫名 表名 > 腳本名;
導出整個數據庫結構和數據
mysqldump -h localhost -uroot -p123456 database > dump.sql
導出單個數據表結構和數據
mysqldump -h localhost -uroot -p123456 database table > dump.sql
導出整個數據庫結構(不包含數據)
mysqldump -h localhost -uroot -p123456 -d database > dump.sql
導出單個數據表結構(不包含數據)mysqldump -h localhost -uroot -p123456 -d database table > dump.sql