mariadb
mysql数据库
在安装mariadb之前应将虚拟机的网络及yum源作如下修改:
DEVICE=eth0
BOOTPROTO=none
IPADDR=172.25.254.101
PREFIX=24
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
PERSISTENT_DHCLTENT=1
systemctl restart network
(2).修改yum源:vim /etc/yum.repos.d/rhel_dvd.repo
# Created by cloud-init on Thu, 10 Jul 2014 22:19:11 +0000
[rhel_dvd]
gpgcheck = 0
enabled = 1
baseurl = http://172.25.254.250/rhel7
name = Remote classroom copy of dvd
1.
yum install mariadb-server -y ##安装
mysql
vim /etc/my.cnf
(skip-networking=1) ##此时只允许通过套接字文件进行本地连接,阻断所有来自网络的tcp/ip连接。
netstat -antlpe | grep mysql
mysql
mysql_secure_installation ##使用mysql_secure_installation工具进行数据库安全设置,根据提示完成操作:
mysql -uroot -pwestos
mysql -uroot -p
#############数据库的基本sql语句操作###################
1.登陆
mysql -uroot -predhat ##-u表示指定登陆用户,-p表示指定此用户密码
2.查询
show databases; ##显示数据库(注意末尾加分号)
show tables; ##显示当前库中表的名称
select * from user; ##查询user表中的所有内容(*可以用表)
desc user; ##查询user表的结构(显示所有子段的名称)
3.数据库及表的建立
create database westos; ##创建westos库
create table linux( ##创建linux表,并且linux表含有两个字段,username,password
username varchar(15) not null, ##username字段,字符长度最大15个,并且不能为空password varchar(15) not null
);
insert into linux values ('nameuser1','passwd1'); ##向linux表中插入数据,username字段的数据为user1
insert into linux values ('user3','passwd123');); ##插入password字段的数据是用password加密过的
4.更新数据库信息
update linux set password=password('passwd2') where username=user1; ##更新法user1的密码
alter table linux add age varchar(4); ##添加age字段到linux表的最后一列
alter table linux add age varchar(5) after name ##添加age字段到name字段之后
alter table linux drop age ##删除age字段
5.删除数据库
delete from linux where username='user1'; ##从linux表中删除user1的数据
drop database westos; ##删除westos库
6.数据库的备份
mysqldump -u root -pwestos --all-database ##备份所有表中的所有数据
mysqldump -u root -pwestos westos ##备份westos库
mysqldump -uroot -pwestos westos linux > /mnt/linux.sql ##备份westos库中的linux表
mysqldump -uroot -pwestos westos test > /mnt/test.sql ##备份westos库中的test表
mysql -uroot -pwestos -e "create database westos;" ##建立westos库
mysql -uroot -pwestos westos < /mnt/westos.sql ##把数据导入westos库中
7.用户授权
create user [email protected] identified by 'lee'; ##建立用户lee,此用户只能通过本机登陆
create user [email protected]'%' identified by 'lee'; ##建立用户lee,此用户只能通过网络登陆
grant insert,update,delete,select on westos.test to [email protected]; ##用户权限
show grants for [email protected]'%' ##查看用户授权
show grants for [email protected]
revoke delete on westos.test from [email protected]; ##去除用户授权权力
drop user [email protected]'%' ##删除用户
8.密码修改
mysqladmin -uroot -pwestos password lee ##修改超级用户密码
mysqld_safe --skip-grant-tables & ##开启mysql登陆接口并忽略授权表
update mysql.user set Password=password('123') where User='root'; ##更新超级用户密码信息
kill -9 mysqlpid
systemctl start mariadb ##重新开启mysql
mysql -uroot -p123 ##登陆测试
########################数据库的网页管理工具#################################################
yum install httpd -y ##安装http
systemctl enable httpd
systemctl stop firewalld ##关闭防火墙
systemctl disable firewalld
phpMyAdmin-3.4.0-all-languages.tar.bz2
tar zxf phpmysqladmin-xxxxx.tar.gz -C /var/www/html ##将下载的压缩包解压到指定的路径
mv phpMyAdmin-3.4.0-all-languages/ mysqladmin ##将该文件移至mysqladmin
cp -p config.sample.inc.php config.inc.php ##复制
vim config.inc.php ##修改
17 $cfg['blowfish_secret'] = 'mysql'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
systemctl restart httpd ##重启服务
http://172.25.254.180/mysqladmin ##此处的172.25.254.180为虚拟机的ip