標籤:esc server alter 操作 ant maria 添加 from ima
mysql(mariadb)
==========
yum install mariadb-server
mysqladmin -uroot -predhat password westos #修改本地mysql root密碼
mysqladmin -uroot -predhat -h 192.168.0.188 password westos #修改遠程192.168.0.188 mysql伺服器 root密碼
mysql_secure_installation #第一次安裝mysql以後通過這條命令可以對mysql進行設定
(配置)
*******增刪改查*******
mysql -uroot -predhat #從本機登入mysql資料庫
show databases; #顯示資料庫
use mysql; #進入資料庫
show tables; #顯示資料庫中的表
desc user; #查看user表的資料結構
flush privileges; #重新整理資料庫資訊
select host.user,password from user; #查詢user表中的host,user,password欄位
select * from mysql.user; # 查詢mysql庫下的user表中的所有
create database westos; #建立westos資料庫
use westos;
create table linux( #建立表,username,password欄位
username varchar(15) not null,
#字元長度 #不可為空白
password varchar(15) not null
);
insert into linux values (‘user1‘,‘passwd1‘); #在linux表中插入值為username = user1,password = password1
update linux set password=password(‘passwd2‘) where username=user1; #更新linux表中user1 的密碼為password2
delete from linux where username=user1; #刪除linux表中user1的所以內容
ALTER TABLE linux ADD age varchar(4) BEFORE password #在name欄位後添加欄位age
ALTER TABLE linux DROP age # 刪除age欄位
*******使用者權限管理******
grant select on *.* to [email protected] identified by ‘passwd1‘; 授權wesots 密碼為passwd1 #並且只能在本地 查詢資料庫的所以內容
REVOKE SELECT ON *.* from [email protected]
grant all on mysql.* to [email protected]‘%‘ identified by ‘passwd2‘; 授權user2 密碼為passwd2 #可以從遠程任意主機登入mysql 並且可以對mysql資料庫任意操作
********備份*******
/var/lib/mysql
mysqldump -uroot -predhat mysql > mysql.bak #備份mysql庫到mysql.bak
mysql -uroot -predhat westos < mysql.bak #恢複mysql.bak 到westos庫
*******mysql密碼恢複******
systemctl stop mariadb #關閉mysql
mysqld_safe --skip-grant-tables & #跳過grant-tables授權表 不需要認證登入本地mysql資料庫
update mysql.user set password=password(‘westos‘) where user=‘root‘;
#更新mysql.user 表中條件為root使用者的密碼為加密westos
systemctl restart mariadb #重啟mysql
mysql(mariadb)