您好,登錄后才能下訂單哦!
基本操作
show databases;
use 庫(kù)名;
show tables;
create table 表名 (字段設(shè)定列表);
describe 表名;
create database 庫(kù)名;
drop database 庫(kù)名;
drop table 表名;
delete from 表名;
select * from 表名;
修改新密碼
方法一(我常用的)
在終端輸入:mysql -u用戶名 -p密碼
use mysql;
update user set password=PASSWORD('新密碼') where user='用戶名';
flush privileges; #更新權(quán)限
quit; #退出
方法二:
用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法三:
用mysqladmin
mysqladmin -u root password "newpass"
如果root已經(jīng)設(shè)置過密碼,采用如下方法
mysqladmin -u root password oldpass "newpass"
方法四:
在丟失root密碼的時(shí)候,可以這樣
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
權(quán)限
一、創(chuàng)建用戶并授權(quán)
格式:GRANT 權(quán)限 ON 庫(kù).表 TO '用戶名'@'指定IP' identified by '密碼';
GRANT ALL PRIVILEGES ON *.* TO 'daxiong1'@'%' identified by 'daxiong1';
flush privileges;【讓上面授權(quán)的操作生效】
GRANT ALL PRIVILEGES ON *.* TO 'daxiong2'@'192.168.8.100' identified by 'daxiong2';
flush privileges;【讓上面授權(quán)的操作生效】
驗(yàn)證:在windows中用Navicat Lite for MySQL工具,使用上面的2個(gè)用戶,登錄咱們的Mysql服務(wù)器!
GRANT select ON *.* TO 'daxiong3'@'%' identified by 'daxiong3';
flush privileges;【讓上面授權(quán)的操作生效】
show grants for 用戶;【查看指定用戶擁有的權(quán)限】
revoke all privileges on *.* from '用戶'@'%';【收回某用戶所有權(quán)限】
當(dāng)用戶權(quán)限是USAGE時(shí),這個(gè)權(quán)限最小,他只能登錄!
【萬能的修改密碼】
update mysql.user set password=password('新密碼') where user='用戶名';
【讓權(quán)限生效】
flush privileges;
show full processlist; 【查看有哪些用戶在登錄】
kill 指定用戶的id 【強(qiáng)制退出指定用戶】
二、增加新用戶(借鑒網(wǎng)上的的文章)
格式:grant 權(quán)限 on 數(shù)據(jù)庫(kù).* to 用戶名@登錄主機(jī) identified by "密碼"
查看用戶的權(quán)限show grants for root;
revoke 權(quán)限 on 數(shù)據(jù)庫(kù).* from username;
設(shè)置權(quán)限時(shí)必須給出一下信息
1,要授予的權(quán)限
2,被授予訪問權(quán)限的數(shù)據(jù)庫(kù)或表
3,用戶名
grant和revoke可以在幾個(gè)層次上控制訪問權(quán)限
1,整個(gè)服務(wù)器,使用 grant ALL 和revoke ALL
2,整個(gè)數(shù)據(jù)庫(kù),使用on database.*
3,特點(diǎn)表,使用on database.table
4,特定的列
5,特定的存儲(chǔ)過程
user表中host列的值的意義
% 匹配所有主機(jī)
localhost localhost不會(huì)被解析成IP地址,直接通過UNIXsocket連接
127.0.0.1 會(huì)通過TCP/IP協(xié)議連接,并且只能在本機(jī)訪問;
::1 ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1
MySQL grant 權(quán)限,分別可以作用在多個(gè)層次上。
1. grant 作用在整個(gè) MySQL 服務(wù)器上:
grant select on *.* to dba@localhost; -- dba 可以查詢 MySQL 中所有數(shù)據(jù)庫(kù)中的表。
grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有數(shù)據(jù)庫(kù)
2. grant 作用在單個(gè)數(shù)據(jù)庫(kù)上:
grant select on testdb.* to dba@localhost; -- dba 可以查詢 testdb 中的表。
3. grant 作用在單個(gè)數(shù)據(jù)表上:
grant select, insert, update, delete on testdb.orders to dba@localhost;
4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to dba@localhost;
5. grant 作用在存儲(chǔ)過程、函數(shù)上:
grant execute on procedure testdb.pr_add to ’dba’@’localhost’
grant execute on function testdb.fn_add to 'dba'@'localhost'
grant 普通 DBA 管理某個(gè) MySQL 數(shù)據(jù)庫(kù)的權(quán)限。
grant all privileges on testdb to 'dba'@'localhost'
其中,關(guān)鍵字 “privileges” 可以省略。
grant 高級(jí) DBA 管理 MySQL 中所有數(shù)據(jù)庫(kù)的權(quán)限。
grant all on *.* to 'dba'@'localhost'
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。