天天看點

linux--mariadb資料庫

一、安裝登陸

1.安裝并開啟服務

yum install mariadb-server.x86_64 

systemctl start mariadb

2.安全初始化

   ) 預設情況下,資料庫的網絡接口時打開的

     為了安全需要關閉此接口

netstat -antple | grep mysql  

圖示:網絡接口

<a href="https://s5.51cto.com/oss/201711/21/f2958d2dc41c7f88f39b3a97221cc128.png-wh_500x0-wm_3-wmp_4-s_2827758384.png" target="_blank"></a>

vim /etc/my.cnf

10   skip-networking=1              

systemctl restart mariadb.service

圖示:關閉接口

<a href="https://s2.51cto.com/oss/201711/21/d5cdb81d4aa19606b48658225d86f617.png-wh_500x0-wm_3-wmp_4-s_3846402537.png" target="_blank"></a>

  )資料庫初始狀态設定資訊時不安全的的,需要做以下設定

mysql_secure_installation

mysql -uroot -p

Enter password: 

圖示:可以直接進去

<a href="https://s2.51cto.com/oss/201711/21/dc32941f423aba489db9c35f4d7b0edc.png-wh_500x0-wm_3-wmp_4-s_3598975230.png" target="_blank"></a>

圖示:加密以後進不去

<a href="https://s5.51cto.com/oss/201711/21/f0648a6878a2c493da8b79c75c244d00.png-wh_500x0-wm_3-wmp_4-s_1677917775.png" target="_blank"></a>

圖示:輸入密碼以後可以進入

3.密碼的管理

)修改密碼

mysqladmin -uroot -pwestos password lee

測試:

mysql -uroot -plee

圖示:-p密碼可以直接進去

<a href="https://s2.51cto.com/oss/201711/21/50e2884b15d938da301129cdb81589b2.png-wh_500x0-wm_3-wmp_4-s_1534550496.png" target="_blank"></a>

)當超級使用者密碼忘記時:

systemctl stop mariadb

mysqld_safe --skip-grant-tables &amp;

mysql 

update mysql.user set Password=password('westos')where User='root'--&gt;;

ps aux | grep mysql

kill -9 mysql的所有程序id

圖示:mysql的所有程序ID

<a href="https://s4.51cto.com/oss/201711/21/2910e2a67983f55fbc6cf3181146c752.png-wh_500x0-wm_3-wmp_4-s_1687083716.png" target="_blank"></a>

圖示:直接進入背景修改密碼

<a href="https://s2.51cto.com/oss/201711/21/c58ec7db3a5e489d13c68cddf975529e.png-wh_500x0-wm_3-wmp_4-s_2754432021.png" target="_blank"></a>

mysql -uroot -pwestos

圖示:測試成功

<a href="https://s1.51cto.com/oss/201711/21/2ffea9feefab047ef44093476de8dbf4.png-wh_500x0-wm_3-wmp_4-s_1785617608.png" target="_blank"></a>

二、mysql使用指令

1.資料庫的管理

)建立

SHOW DATABASES;            ##列出庫

CREATE DATABASE westos;          ##建立庫

USE westos;                  ##建立表

CREATE TABLE linux (

    -&gt; username varchar(50) notnull,

    -&gt; password varchar(50) notnull

    -&gt; );

DESC  linux;                  ##檢視表結構

INSERT INTO lee VALUES ('lee','123');       ##插入資料到lee表中

SELECT * FROM lee;                    ##查詢所有字段在lee表中

SELECT username,password from linux;        ##查詢指定字段在lee表中

圖示:列出庫

<a href="https://s4.51cto.com/oss/201711/21/4da0a81512dd141d95f27d1c0236a2db.png-wh_500x0-wm_3-wmp_4-s_1906821235.png" target="_blank"></a>

圖示:檢視表結構

<a href="https://s2.51cto.com/oss/201711/21/c7fb22f78fc0718365af850979282a4f.png-wh_500x0-wm_3-wmp_4-s_1567787221.png" target="_blank"></a>

圖示:查詢所有字段在lee表中

)更改

UPDATE Linux SET password=password('lee') where username='lee';

ALTER TABLE linux ADD class varchar(20);               

ALTER TABLE linux DROP CLASS;

ALTER TABLE linux ADD age varchar(20) AFTER password;

ALTER TABLE linux RENAME redhat;

圖示:更改

<a href="https://s4.51cto.com/oss/201711/21/28077e19532dc4129782d41015554839.png-wh_500x0-wm_3-wmp_4-s_4015972444.png" target="_blank"></a>

)删除

SELECT username,password from lee;         ##檢視使用者,密碼            

DELETE FROM redhat where username='lee';     ##删除使用者

DROP TABLE redhat;                    ##删除表

DROP DATABASE westos;                  ##删除庫

ALTER TABLE linux ADD class varchar(20);

圖示:删除表

linux--mariadb資料庫

圖示:删除庫

linux--mariadb資料庫

圖示:删除字段

linux--mariadb資料庫

圖示:删除表内資訊

linux--mariadb資料庫

)使用者授權

CREATE USER lee@'localhost' identified by 'westos';  ##建立使用者身份

GRANT SELECT,INSERT on westos.* TO lee@localhost;    ##授權

SHOW GRANTS FOR lee@localhost;                 ##檢視授權

REVOKE INSERT ON westos.* FROM lee@localhost;       ##撤銷授權

圖示:檢視授權

<a href="https://s3.51cto.com/oss/201711/21/8ad84d1a93e4c7dd2ea6c26b5c81f3cd.png-wh_500x0-wm_3-wmp_4-s_3424718949.png" target="_blank"></a>

2.資料庫的備份

mysqldump -uroot -pwestos westos &gt; /mnt/westos.sql

mysqldump -uroot -pwestos westos --no-data

mysqldump -uroot -pwestos --all-database

mysqldump -uroot -pwestos --all-database --no-data

圖示:備份

<a href="https://s1.51cto.com/oss/201711/21/f5ac7b8cccf8467e44a6caf71cf70750.png-wh_500x0-wm_3-wmp_4-s_2652627130.png" target="_blank"></a>

恢複方式1

mysql -uroot -pwestos -e "CREATE DATABASE westos;"

mysql -uroot -pwestos westos &lt; /mnt/westos.sql

恢複方式2

vim /mnt/westos.sql

CREATE DATABASE westos;

USE westos;

mysql -uroot -pwestos &lt; /mnt/westos.sql

圖示:修改配置

<a href="https://s5.51cto.com/oss/201711/21/def932e6b4c0589744d5d885db6c5d14.png-wh_500x0-wm_3-wmp_4-s_3667618316.png" target="_blank"></a>

三、安裝phpmyadmin 資料庫圖形管理

1.下載下傳phpMyAdmin

2.yum install php php-mysql -y

3.systemctl restart httpd

4.cp -rp phpMyAdmin-3.4.0-all-languages.tar.bz2 /var/www/html/

5.tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2

6.mv phpMyAdmin-3.4.0-all-languages mysqladmin

7.cd mysqladmin

8.cp config.sample.inc.php config.inc.php

9.vim config.inc.php

$cfg['blowfish_secret'] = 'ba17clec07d65003';

圖示:安裝php、php-mysql

<a href="https://s2.51cto.com/oss/201711/21/665114f972f7b425c4159bf9bd9308b0.png-wh_500x0-wm_3-wmp_4-s_255090251.png" target="_blank"></a>

四.安裝Discuz

1.下載下傳Discuz_X3.2_SC_UTF8.zip

2.cd /mnt

3.unzip Discuz_X3.2_SC_UTF8.zip   ##解壓檔案

4.setenforce 0              ##将selinux設定為關閉   

5.chmod 777 upload -R          ##給upload權限

圖示:Discuz簡介

<a href="https://s5.51cto.com/oss/201711/21/9c98021332ba57c69f0a4cc4d9be4306.png-wh_500x0-wm_3-wmp_4-s_3858159644.png" target="_blank"></a>

##end##

版權聲明:原創作品,如需轉載,請注明出處。否則将追究法律責任

本文轉自 無緣 51CTO部落格,原文連結:http://blog.51cto.com/13352594/1983914