第三課unit8 mariadb
1.yum intall mariadb-server -y ##安裝mariadb服務
systemctl start mariadb ##開啟服務
vim /etc/my.cnf ##修改配置文件
systemctl restart mariadb #重啟服務
修改內容
**跳過符號鏈接
mysql_secure_installtion ##mysql加密
**Enter current password for root (enter for none): ##數據庫原始密碼,直接回車
**Change the root password? [Y/n] y ##是否設定數據庫root密碼
New password: ##輸入密碼
Re-enter new password: ##重復密碼
**Remove anonymous users? [Y/n] y ##是否刪除匿名用戶訪問權限
**Disallow root login remotely? [Y/n] y ##是否禁止超級用戶遠程登錄
**Remove test database and access to it? [Y/n] y ##是否刪除測試數據
**Reload privilege tables now? [Y/n] y ##重新加載服務
2.數據庫的基本sql語句操作
(1)登錄
mysql -uroot -p ##-u代表用戶 -p密碼
(2)查詢
show databases; ##顯示數據庫
use mysql; ##進入MySQL庫
show tables; ##顯示數據庫裏表的名稱
select * from user; ##查詢user表中所有內容
desc user; ##查詢user表的結構 (顯示表頭)
(3)數據庫的建立
create database westos; ##建立westos庫
create table linux( ##建立Linux表,並且有username和password兩個字段
username varchar(15) not null,
password varchar(15) not null
);
insert into linux values (‘user1‘,‘123‘) ##給Linux表裏寫入內容
(4)數據庫的更新
update linux set password=password(‘456‘) where username=‘user1‘; ##加密更新user1密碼
update linux set password=password(‘456‘) where (username=‘user2‘ or username=‘user3‘; ##更新user2和user3密碼
delete from linux where where username=‘user1‘; ##刪除user1密碼
alter table linux add age varchar(4); ##在Linux表最後添加age列
alter table linux add year varchar(4)after age ##在age字段後添加year字段
alter table linux drop age ; ##刪除age字段
(5)刪除數據庫
drop table linux ##刪除Linux表
drop database westos ##刪除westos庫
(6)數據庫的備份
mysqldump -u root -p123 --all -database ##備份表中所有數據
mysqldump -u root -p123 --all -database --no-data ##備份所有表,不備份數據
mysqldump -u root -p123 westos ##備份westos庫
mysqldump -u root -p123 westos > /mnt/westos.sql ##備份westos庫保存到westos.sql
mysqldump -u root -p123 westos linux > /mnt/linux.sql ##備份westos庫中的Linux表
mysql -u root -p123 -e "create database westoss;" ##建立westos庫
mysql -u root -p123 westos < /mnt/linux.sql ##導入數據到westos庫
**測試
(7)用戶授權
create user [email protected] identified by ‘ws‘; ##創建用戶ws,只能通過本機登錄
create user [email protected]%‘ identified by ‘ws‘; ##創建用戶ws,只能通過網絡登錄
grant insert,update,delete,select on westos.linux to [email protected] ##用戶授權
revoke delete on westos.linux from [email protected] ##刪除用戶授權
drop user [email protected]%‘ ##刪除用戶
(8)修改密碼
mysqladmin -uroot -p123 password 456
mysqld_safe --skip-grant-table & ##開啟MySQL登錄接口忽略授權表
mysql ##不要密碼登錄
update mysql.user set Password=password(‘123‘) where User=‘root‘ ##更新root密碼
ps aux | grep mysql ##過濾MySQL進程並結束
kill -9
systemctl start maraidb ##重啟MySQL
3.數據庫網頁管理工具
yum install httpd php phy-mysql -y ##安裝服務
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html ##解壓文件到指定目錄
mv phpMyAdmin-3.4.0-all-languages/ mysqladim ##重命名文件
cd mysqladim
cp -p config.sample.inc.php config.inc.php ##復制模板
vim config.inc.php ##編輯配置文件
systemctl restart httpd
**修改配置文件內容
、
**測試
第三課unit8 mariadb