欢迎投稿

今日深度:

进入mariadb_MariaDB基本命令,MariaDB数据库

进入mariadb_MariaDB基本命令,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

www.htsjk.Com true http://www.htsjk.com/mariadb/45950.html NewsArticle 进入mariadb_MariaDB基本命令,MariaDB数据库 MariaDB名称来自Michael Widenius的女儿Maria的名字。MariaDB数据库管理系统是MySQL的一个分支主要由开源社区在维护采用GPL授权许可 MariaDB的目的是完全...
评论暂时关闭