mysql数据库

安装

wKioL1g80y7R0awOAAKSqif0vcA523.png-wh_50

yum installmariadb-server.86_64 -y

关闭数据库接口(为了安全)

vim /etc/my.cnf

symbolic-links=1


配置mysql安全机制

mysql_secure_installation

(一路回车输密码 ^_^

wKiom1g80zzigboxAAGKTiD58WI011.png-wh_50

wKiom1g801uwMN7rAAIk4WzsNZA053.png-wh_50

登陆mysql

关键命令:(其余请大家根据需要百度一下啦~ ^.^

mysql -uroot -p密码

 wKioL1g802iBkuFnAAE8EJ-OTGM773.png-wh_50

SHOW DATABASES; (显示数据库)

wKiom1g803aRgLxxAABpnpKy9NA007.png-wh_50

USER mysql; (进入数据库)

SHOW TABLES;(显示数据库的表)

wKioL1g803-gnKl7AACz-B_TW1E480.png-wh_50

SELECT Host.User.Password FROM user;(查询user表中的Host.User.Password字段)

 

wKiom1g805CAtyxoAAJRMR8_PdI619.png-wh_50

wKioL1g805KBpGcaAAGvThN_A1c947.png-wh_50

CREATE DATABASE dangdang (创建DD数据库)

wKioL1g8053Ti8PpAAC_rWbWuu8508.png-wh_50

CREATE TABLE DD(创建表)

wKiom1g806bhDuewAABLE-TVDu0380.png-wh_50

DESC DD(显示表的形态)

wKiom1g806_AgQ5PAACpyB4OZf0387.png-wh_50

INSERT INTO DD VALUES (在表中插入数据)

wKioL1g809LAGBt7AADoym4yVv4696.png-wh_50

wKiom1g809PjMSlvAAFOtnEcMRQ474.png-wh_50

wKioL1g809SzfBNIAAEmwcOyGqY832.png-wh_50

ALTER TABLE DD ADD class varchar(8) AFTER password; (在表中加入一列)

wKioL1g80-KDmzrpAADz9ZGdd2s282.png-wh_50

UPDATE DD SET WHERE username=tom;(在新加的一列中写入数据)

wKiom1g80-zioETfAADvUkXbgzU637.png-wh_50

DELETE FROM DD WHERE username='tom';  (删除表的一行)

wKioL1g80_ixeQPvAAC90jV25mA564.png-wh_50

DROP TABLE DD  (删除表)

wKiom1g81ALRRRymAACJNqunuBs248.png-wh_50

DROP DATABASES dangdang(删除数据库)

 

 

create user dangdang@localhost indentified by 'westos' (创建本地登陆用户)

wKioL1g81IyDAefVAABloBIno9A874.png-wh_50

wKioL1g81KnhDYmZAAFJW4i1yq4066.png-wh_50

create userdangdang@‘%’indentified by 'redhat'(创建远程登陆用户)

 

grant create on *.* to dangdang@localhost(给dangdang用户create的权限)

wKiom1g81LWye3mmAAE4M__hZqM160.png-wh_50

grant insert on *.* to dangdang@localhost(给dangdang用户insert的权限)

wKiom1g81MeSYKdSAAFKKftrEnU722.png-wh_50

show grants for dangdang@localhost(查看dangdang用户的权限)

 

flush privileges (刷新)

revoke create on *.* from dangdang@localhost(删除dangdang用户create的权限)


wKioL1g81NaBcnhFAAGtGSn7zjg656.png-wh_50

 

忘记root用户密码

systemctl stop mariadb

mysqld_safe--skip-grant-tables &

mysql -uroot

UPDATE mysql.userset Password=password('dangdang')WHERE User='root'


wKiom1g81OLjEb_RAAECXOwoK-A473.png-wh_50

结束所有mysql进程

systemctl startmariadb

 

更改root用户密码:(已知密码)

mysqladmin -uroot -pdangdang  -password redhat


wKioL1g81O3grYxGAAFbMv5yq00722.png-wh_50

数据库的备份

mysqldump -uroot -predhat DD > /mnt/DD.sql


wKiom1g81PXDzxSFAAGUI78rliM817.png-wh_50

mysqldump -uroot -predhat DD < /mnt/DD.sql

mysqldump -uroot-predhat --no-date DD > /mnt/DD.sql(只导入框架,不导入里面的数据)




wKiom1g81QGxpDLCAACd6WDO28s470.png-wh_50

wKioL1g81QLBRJ10AAFMpedNAWM654.png-wh_50

mysql -uroot-predhat -e “SHOW DATABASES”(非交互式登陆)


wKioL1g81ROBsL6KAACGZWAu-DI161.png-wh_50

 

网页方式管理数据库

 

yum insatll httpd-y

systemctl stopfirewalld

systemctl starthttpd

cd /var/www/htmp

php压缩包放到此目录里面,解压,重命名

cp -p config.sample.inc.php config.inc.php

yum insatll php –y


wKiom1g81R2DjsEbAAGyVgGks_o621.png-wh_50

yum insatllphp-mysql –y


wKiom1g81SXxlE-AAAIdYEiz0fs103.png-wh_50

通过网页访问:http://ip/myadmin