數據庫

數據庫

yum install mariadb-server -y

systemctl start mariadb

netstat -antlpe | grep mysqld

 

vim /etc/my.cnf

---------------------

# instructions in http://fedoraproject.org/wiki/Systemd

skip-networking=1      

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

---------------------

systemctl restart mariadb

netstat -antlpe | grep mysqld

mysql_secure_installation        //爲數據庫設置安全信息

mysql -uroot -p               //登錄數據庫

ENTER PASSWD;                   //輸入密碼

 

數據庫的操作

show databases;      //顯示數據庫

use westos;           //進入數據庫

show tables;         //顯示數據庫中的表

desc linux;           //查看user表的數據結構

select host,user,password from user; //查詢user表中的host,user,password字段 

create database westos;            //創建westos數據庫

use westos;

wKiom1jCMxHR9iXwAADCzBtH6DM172.png-wh_50

create table linux (

username varchar(13) not null,

password varchar(12) not null

);

wKioL1jCM2-SgI25AAFGJCzHUA0514.png-wh_50

wKiom1jCNNKjUB0ZAACqQhi_ZIY227.png-wh_50

select * from westos.linux;

wKioL1jCNFigcgmDAACAPpN7TSM298.png-wh_50

刪除user1的信息

wKioL1jCNSXwHBaPAAC_0D7I8XQ336.png-wh_50

 

 

 

數據庫的備份

  mysqldump -uroot -pwestos westos > /mnt/westos.sql   //將數據備份到/mnt/westos.sql中

  mysql -uroot -pwestos westos -e "DROP DATABASE westos;"//刪除庫westos

  mysql -uroot -pwestos -e "SHOW DATABASES;"  //查看庫

 wKiom1jCNU_SB-gnAALxIurD41I884.png-wh_50  


 cd /mnt

 ls

 cat westos.sql

 mysql -uroot -pwestos -e "CREATE DATABASE westos;"//重新創建庫westos

 mysql -uroot -pwestos westos < /mnt/westos.sql   //恢復庫的原始內容

wKioL1jCNXPRhS_eAACXzqakBmw038.png-wh_50

   mysql -uroot -pwestos                           //登陸數據庫查看


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章