MariaDB基本命令

    MariaDB名稱來自Michael Widenius的女兒Maria的名字。MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL授權許可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕鬆成爲MySQL的代替品。

1.數據庫安裝並初始化

yum install mariadb-server.x86_64 -y    ##安裝數據庫
systemctl start mariadb         ##開啓數據庫服務
netstat -antlupe|grep mysql     ##查看數據庫的接口信息
mysql                   ##測試能否打開數據庫
vim /etc/my.cnf             ##關閉數據庫對外接口
    skip-networking=1       ##在第6行添加命令(跳過網絡服務)
:wq
systemctl restart mariadb       ##重啓服務
netstat -antlupe|grep mysql     ##此時查看數據庫端口已經關閉
mysql_secure_installation       ##數據庫初始化,這裏我們輸入密碼後全部選擇y

2.MYSQL基本操作指令

mysql -uroot -p123  ##進入數據庫(這裏不要養成習慣因爲輸入密碼時明文的)
**1)查看****重點內容**
show databases;                 ##顯示數據庫
use mysql;                  ##進入數據庫
show tables;                    ##顯示數據庫中的表
select * from mysql.user;           ##查詢mysql庫下的user表中的數據
desc user;                  ##查看user表的數據結構
flush privileges;               ##刷新數據庫信息
select host,user,password from user;        ##查詢user表中的host,user,password字段
select host,user,password from user where host="::1"##查詢表中字段中有關::1的數據

這裏寫圖片描述
這裏寫圖片描述

2)創建
create database westos;             ##創建westos數據庫
use westos;                 ##進入westos數據庫
create table linux(             ##創建表,user,passwd字段
user varchar(15) not null,
passwd varchar(15) not null             ##varchar可變型字符變量
 );
insert into linux values ('student','student');     ##在linux表中插入值爲student student
select * from linux;                    ##查詢linux中的數據

這裏寫圖片描述
這裏寫圖片描述

3)更改
alter table linux rename messages;          ##將linux表重命名爲messages
alter table linux add age varchar(4);           ##添加age字段到linux表中
ALTER TABLE linux DROP age;             ##刪除age字段
ALTER TABLE linux ADD age VARCHAR(5) AFTER name;    ##在name字段後添加字段age
ALTER TABLE linux ADD age VARCHAR(5)            
update linux set password=student where username=student;##更新linux表中user1的密碼爲password2
4)刪除
delete from linux where username=user1;         ##刪除linux表中user1的所有內容
drop table linux;                   ##刪除linux表
drop database westos;                   ##刪除westos數據庫
5)用戶授權
CREATE USER lee@localhost identified by 'lee';      ##創建用戶lee密碼爲lee
grant select insert on  *.* to lee@localhost;   ##授權user1 密碼爲passwd1只能在本地 查詢數據庫的所以內容 
grant all on mysql.* to lee@'%' identified by 'lee2';   ##授權user2 密碼爲passwd2  可以從遠程任意主機登錄mysql 並且可以對mysql數據庫任意操作
show grants for lee@localhost;          ##查看已經修改的權限;        
revoke insert on *.* from lee@localhost;    ##刪除掉用戶lee的添加數據權限;
6)備份
/var/lib/mysql
mysqldump -uroot -p123 westos > /mnt/mysql.sql  ##備份mysql庫到mysql.bak
mysql -uroot -p123 -e "DROP database westos"
mysql -uroot -p123 westos < /mnt/mysql.sql      ##恢復mysql.bak 到westos庫
7)mysql 密碼恢復
/etc/init.d/mysqld stop
或者systemctl stop mariadb
mysqld_safe --skip-grant-tables &   ##跳過grant-tables授權表  不需要認證登錄本地mysql數據庫
update mysql.user set password=password('westos') where user='root';    ##更新mysql.user 表中條件爲root用戶的密碼爲加密westos
修改完成後
ps aux|grep mysql
kill -9 +端口號 結束所有關於mysql的進程
systemctl start mysql 

3.php-mysq

@@php -m 可以查看php所支持的服務,因爲本身默認不支持mysql
所以需要安裝php-mysql模塊才能使用@@
phpmyadmin

yum install php php-mysql httpd mysql mysql-server  ##安裝需要的服務
tar jxf phpmyadmin-*.tar.bz2 -C /var/www/html       ##將下載好的東西解壓
mv phpmyadmin phpadmin                  ##重命名
cp config.sample.inc.php config.inc.php         ##複製文件
vim config.inc.php                  ##php3.4版本不需要
add 
$cfg['blowfish_secret'] = 'test';
/etc/init.d/httpd start

測試:http://172.25.254.117/phpadmin
這裏寫圖片描述
這裏寫圖片描述

4.discuz論壇建立

下載DISCUZ壓縮包

unzip解壓
cp -r upload /var/www/html/
chomd 777 /var/www/html/upload/* -R

測試:http://172.25.254.117/upload
這裏寫圖片描述

發佈了32 篇原創文章 · 獲贊 12 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章