1. 程式人生 > >第三課unit8 mariadb

第三課unit8 mariadb

password 配置文件 current 數據庫 enter

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