標籤:localhost password databases 使用者名稱 describe
基本操作
show databases;
use 庫名;
show tables;
create table 表名 (欄位設定列表);
describe 表名;
create database 庫名;
drop database 庫名;
drop table 表名;
delete from 表名;
select * from 表名;
修改新密碼
方法一(我常用的)
在終端輸入:mysql -u使用者名稱 -p密碼
use mysql;
update user set password=PASSWORD(‘新密碼‘) where user=‘使用者名稱‘;
flush privileges; #更新許可權
quit; #退出
方法二:
用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘newpass‘);
方法三:
用mysqladmin
mysqladmin -u root password "newpass"
如果root已經設定過密碼,採用如下方法
mysqladmin -u root password oldpass "newpass"
方法四:
在丟失root密碼的時候,可以這樣
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user=‘root‘;
mysql> FLUSH PRIVILEGES;
許可權
一、建立使用者並授權
格式:GRANT 許可權 ON 庫.表 TO ‘使用者名稱‘@‘指定IP‘ identified by ‘密碼‘;
GRANT ALL PRIVILEGES ON *.* TO ‘daxiong1‘@‘%‘ identified by ‘daxiong1‘;
flush privileges;【讓上面授權的操作生效】
GRANT ALL PRIVILEGES ON *.* TO ‘daxiong2‘@‘192.168.8.100‘ identified by ‘daxiong2‘;
flush privileges;【讓上面授權的操作生效】
驗證:在windows中用Navicat Lite for MySQL工具,使用上面的2個使用者,登入咱們的Mysql伺服器!
GRANT select ON *.* TO ‘daxiong3‘@‘%‘ identified by ‘daxiong3‘;
flush privileges;【讓上面授權的操作生效】
show grants for 使用者;【查看指定使用者擁有的許可權】
revoke all privileges on *.* from ‘使用者‘@‘%‘;【收回某使用者所有許可權】
當使用者權限是USAGE時,這個許可權最小,他只能登入!
【萬能的修改密碼】
update mysql.user set password=password(‘新密碼‘) where user=‘使用者名稱‘;
【讓許可權生效】
flush privileges;
show full processlist; 【查看有哪些使用者在登入】
kill 指定使用者的id 【強制退出指定使用者】
二、增加新使用者(借鑒網上的的文章)
格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼"
查看使用者的許可權show grants for root;
revoke 許可權 on 資料庫.* from username;
設定許可權時必須給出一下資訊
1,要授與權限
2,被授予存取權限的資料庫或表
3,使用者名稱
grant和revoke可以在幾個層次上控制存取權限
1,整個伺服器,使用 grant ALL 和revoke ALL
2,整個資料庫,使用on database.*
3,特點表,使用on database.table
4,特定的列
5,特定的預存程序
user表中host列的值的意義
% 匹配所有主機
localhost localhost不會被解析成IP地址,直接通過UNIXsocket串連
127.0.0.1 會通過TCP/IP協議串連,並且只能在本機訪問;
::1 ::1就是相容支援ipv6的,表示同ipv4的127.0.0.1
MySQL grant 許可權,分別可以作用在多個層次上。
1. grant 作用在整個 MySQL 伺服器上:
grant select on *.* to [email protected]; -- dba 可以查詢 MySQL 中所有資料庫中的表。
grant all on *.* to [email protected]; -- dba 可以管理 MySQL 中的所有資料庫
2. grant 作用在單個資料庫上:
grant select on testdb.* to [email protected]; -- dba 可以查詢 testdb 中的表。
3. grant 作用在單個資料表上:
grant select, insert, update, delete on testdb.orders to [email protected];
4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to [email protected];
5. grant 作用在預存程序、函數上:
grant execute on procedure testdb.pr_add to ’dba’@’localhost’
grant execute on function testdb.fn_add to ‘dba‘@‘localhost‘
grant 普通 DBA 管理某個 MySQL 資料庫的許可權。
grant all privileges on testdb to ‘dba‘@‘localhost‘
其中,關鍵字 “privileges” 可以省略。
grant 進階 DBA 管理 MySQL 中所有資料庫的許可權。
grant all on *.* to ‘dba‘@‘localhost‘
本文出自 “一起來吧” 部落格,請務必保留此出處http://daxionglaiba.blog.51cto.com/11790757/1828090
mysql 的基本操作以及常用命令