Linux--RH254---unit 8 mariadb数据库
来源:互联网 发布:影音后期制作软件大全 编辑:程序博客网 时间:2024/05/18 20:34
一、数据库的基本sql语句操作
1.安装
yum install mariadb-server -y ###安装mariadb
netstat -antlpe | grep mysql ###校验mariadb的监听端口
vim /etc/my.cnf ###编辑/etc/my.cnf文件
skip-networking=1 ###阻断监听
netstat -antlpe | grep mysql ###mariadb的监听端口不存在,此时只允许通过套接字文件进行本地连接,阻断所有来自网络的tcp/ip连接。
mysql_secure_installation ###第一次安装mysql以后通过这条命令可以对mysql进行设置
Enter current password for root (enter for none) 按EnterSet root password? [Y/n] y
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.登陆
mysql -uroot -pwestos ###u表示指定登陆用户,p表示指定此用户密码(密码为明文)
mysql -uroot -p ###密码为加密
Enter password:
3.查询
MariaDB [(none)]> show databases; ###显示数据库
MariaDB [(none)]> use mysql; ###进入mtsql库
MariaDB [mysql]> show tables; ###显示当前库中表的名字
MariaDB [mysql]> select * from user; ###查询user表中的所有内容(*可以用此表中的任何字段来代替,多个字段用逗号分隔)
MariaDB [mysql]> desc user; ###查询user表的结构(显示所有字段的名称)
4.数据库及表的建立
create database westos; ###创建westos库
create table linux( ###创建linux表,含有username,password两个字段
-> username varchar(15) not null, ###添加username字段,字符长度最大15,且不能为空-> password varchar(15) not null ###添加password字段,字符长度最大15,且不能为空
-> );
insert into linux values ('user1',password('123')); ###插入password字段的数据是用password加密过的
5.更新数据库信息
update linux set password=password('456') where username='user2'; ###更新user2的密码
update linux set password=password('456') where ( username='user1' or username='user2' ); ###更新user1和user2的密码
delete from linux where username='user3'; ###删除user3的信息
alter table linux add age varchar(4); ###添加age字段到linux表的最后一列alter table linux add class varchar(4) after password; ###添加class字段到password字段后
alter table linux drop age; ###删除age字段
6.删除数据库
delete from linux where username='user2'; ###从linux表中删除user2的数据
drop table linux; ###删除linux表
drop database westos; ###删除westos库
7.数据库的备份
mysqldump -uroot -pwestos --all-database ###备份所有表中的左右数据
mysqldump -uroot -pwestos --all-database --no-data ###备份所有表,但不备份数据
mysqldump -uroot -pwestos westos ###备份westos库
mysqldump -uroot -pwestos westos linux > /mnt/linux.sql ###备份westos库中的linux表
mysql -uroot -pwestos westos < /mnt/westos.sql ###把数据导入westos库
mysql -uroot -pwestos -e "select * from westos.linux;" ###查看westos库中linux表所有内容
8.用户授权
mysql -uroot -pwestos
select User,Host from mysql.user; ###查看mysql库中user表的User,Host字段
create user redhat@localhost identified by 'redhat'; ###建立用户redhat,此用户只能通过本机登陆
create user redhat@'%' identified by 'redhat'; ###建立用户redhat,此用户可以通过网络登陆
mysql -uredhat -predhat -h localhost ###本机登陆
skip-networking=0 ###开启监听端口,此时本地连接和网络连接皆可
systemctl restart mariadb ###重启mariadb
mysql -uredhat -predhat -h 172.25.254.131 ###网络登陆
grant insert,update,delete,select on westos.linux to redhat@localhost; ###本机登陆用户授权
grant select on westos.linux to redhat@'%'; ###网络登陆用户授权
show grants for redhat@localhost; ###查看用户授权
revoke delete on westos.linux from redhat@localhost; ###删去用户授权权力
drop user redhat@'%'; ###删除用户
9.密码修改
mysqladmin -uroot -pwestos password linux ##在知道密码的情况下修改超级用户密码
systemctl stop mariadb ##关闭Screenshot from 2017-05-16 12-29-41
mysqld_safe --skip-grant-tables & ##开启mysql登陆接口并忽略授权表
mysql ##直接登陆不用密码
update mysql.user set Password=password('123') where User='root'; ##更新超级用户密码信息
kill -9 mysqlpid ##结束进程
systemctl start mariadb ##重新开启mysql
mysql -uroot -p123 ##登陆测试
二、数据库的网页管理工具
1.安装
yum install httpd php php-mysql -y ##安装httpd php php-mysql
systemctl start httpd ##开启httpd
systemctl enable httpd ##开机自启动systemctl stop firewalld ##关闭防火墙
systemctl disable firewalld ##开机自关闭
cd /var/www/html/ ##切换至/var/www/html/
mv phpMyAdmin-3.4.0-all-languages/ mysqladmin ##移动phpMyAdmin-3.4.0-all-languages下所有文件至mysqladmin
cd mysqladmin ##切换至mysqladmin
cp -p config.sample.inc.php config.inc.php ##添加配置文件
vim config.inc.php ##修改配置文件
$cfg['blowfish_secret'] = 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
systemctl restart httpd ##重启httpd
2.访问测试:172.25.254.131/mysqladmin
数据库-->新建数据库redhat-->创建 ##创建redhat库
点击redhat库-->新建linux表,字段2-->执行 ##创建linux表
字段user、password--类型VARCHAR--长度15--保存 ##添加linux表的字段
点击redhat库-->点击linux2表后面的删除-->DROP TABLE linux2(确定) ##删除linux2表
数据库-->勾上redhat-->点击删除-->DROP DATABASE 'redhat'(是) ##删除redhat库
- Linux--RH254---unit 8 mariadb数据库
- Linux--RH254---unit 10 iptables
- Linux--RH254---unit 10 firewalld
- Linux--RH254---unit 7 Samba
- Linux---RH254---unit 6 NFS
- Linux--RH254---unit 5 ISCSI
- Linux--RH254---unit 3 高速缓存DNS
- Linux--RH254---unit 2 高级网络配置
- Linux--RH254---unit 9 apache web服务
- Linux--RH254---unit 11 bash 2
- Linux--RH254---unit 1 ipv6网络的管理
- linux之数据库mariadb
- linux的mariadb数据库
- Linux-mariadb数据库管理
- Linux中的mariadb----数据库
- Linux--RH254---unit4 postfix2
- Linux--RH254---PXE
- Linux--RH254---rh254exam
- Html5斜45度地图+3D模型ARPG系列教程(3)-- 关于如何运行示例项目
- python3如何使用元类
- 只包含因子2 3 5的数
- squid的正反向代理
- Linux运维笔记-文档总结-mariadb数据库的各项操作(全)
- Linux--RH254---unit 8 mariadb数据库
- MATLAB面向对象编程命名空间的使用
- 二叉树遍历
- ASP.NET HttpModule的使用说明
- C和指针 练习 1-3
- Binary Tree K level sum (samsung)
- 在“一带一路”上,有哪些国家?
- 非虚方法的调用
- 无数个骂娘的故事告诉你,千万别做技术合伙人!