mariadb数据库

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

##配置网络
 vim/etc/sysconfig/network-scripts/ifcfg-eth0 写网络配置文件
 systemctl restart network  重启网络
##配置yum源
 vim /etc/yum.repos.d/rhel_dvd.repo 写yum源配置文件
 yum clean all     重置yum源
##修改服务器名字
 hostnamectl set-hostnamemariadb.westos.com 更改本地服务器名字
 hostname 查看本地本地服务器名字

wKiom1kccwDQLOarAABHUVyrhyQ064.png-wh_50

wKioL1kccwDjr3scAABz4zToJRk383.png-wh_50

wKiom1kccwHROyt0AAF_C-2_GKo200.png-wh_50


####### mariadb数据库########### 数据库厂商 mysql  oracle

一 数据库的安装与配置 
    1 yum install mariadb-server -y  ##安装mariadb 

wKiom1kcc2OCXXSKAACN7EinkTw313.png-wh_50

    2 systemctl start mariadb        ##开启mariadb服务
    3 mysql                          ###进入mysql数据库
    4 netstat -antlpe | grep mysql   ###查询mysqul
    5 vim /etc/my.cnf               ###mysqul的配置文件
       skip-networking=1

wKioL1kcc2OTohzjAAClhNl8QS4111.png-wh_50

    6 systemctl restart mariadb      ###重启mariadb服务
    7 netstat -antlpe | grep mysqul 
    8 mysql
    9 mysql_secure_installation     ###mysql安全内容配置
       (1)Enter current password for root(enter for none):[Enter]
       (2)Set root password? [Y/n]Y
           New password:                ###输入新密码
           Re-enter new password:       ###确认密码
       (3)Remove anonymous users? [Y/n]Y
       (4)Disallow root login remotely?[Y/n] Y
       (5)Remove test database and accessto it? [Y/n] Y
       (6)Reload privilege tables now?[Y/n] Y 
   10 mysql -uroot -p  
   11 mysql
图:

wKiom1kcc2Sy484LAACpbMs_3XE587.png-wh_50

wKioL1kcc2SSdBLIAADoHR1MHvc650.png-wh_50

wKiom1kcc2XQfo00AADo2zIcyvg640.png-wh_50

wKiom1kcc2WyxQRFAACKmiIka8s777.png-wh_50


二  数据库基本语句
 1 登陆
   (1)mysql -uroot -pqwer1234  ##qwer1234是密码
   (2)mysql -uroot -p  
     Enter password:             ##密码不显示;安全性能高
 2 查询
    (1)show databases;             ###显示数据库

   (2)use mysql                  ###进入mysql库

    (3)show tables;                ###显示当前库中表的名字
    (4)select * from user          ###查询user表中的所有内容(* 可以用表中所有字段来代替)
    (5)desc user;                  ###查询表的结构 (显示所有字段的名称)

wKioL1kcdBiiCSSwAAC-kGDNNBQ506.png-wh_50

wKiom1kcdBigRw6HAABsfUHqaRI424.png-wh_50

wKioL1kcdBnxc4rWAACaFHL7UdA607.png-wh_50

wKiom1kcdBmQgRmlAACKpOMqMfk058.png-wh_50


 3 数据库及表的建立
  (1)create database westos;  ####创建westos库
         show databases;         ###显示数据库

wKioL1kcdGfzHZTCAACgvZN5RNI809.png-wh_50

  (2)use westos               ###进入westos库
       create table linux(      ####linux表
    -> username varchar(15) not null,
    -> password varchar(15) not null); ###表中含有username,password两个字段;字符长度最大为15个,都不为空。(字符长度可根据需要更改)
 
      desc linux;               ###查询表的结构 (显示所有字段的名称)

wKiom1kcdGewCkycAADzELNVsVU340.png-wh_50

  (3)insert into linux values ('user','123'); ###向表中插入数据,
       select * from linux;      ###查询linux表中的所有内容             
      insert into linux values('user1',password('123') );
      ###向表中插入数据,加密密码wKioL1kcdGiimcKDAACmhu0FiTo729.png-wh_50


 4 更新数据库信息
   (1)update linux set password=('234') where username='user1';
        ##### 更新user1的密码
       select * from linux;  ###查询linux表中的所有内容 

wKioL1kcdOyiePTxAACZiCWw3tE118.png-wh_50

   (2)update linux set password=password('123') where  username='user';
        #####更新use的密码,并加密
         select * from linux; 

wKiom1kcdO2y9PqwAACMl_0IZ78766.png-wh_50

   (3)alter table linux add age varchar(4);
       ####增加age字段到表的最后一列
        select * from linux; 

wKiom1kcdO2waiGaAACYs1WiGr8566.png-wh_50

   (4)alter table linux add exam varchar(4) after password;
        ####增加exam字段到指定位置
        select * from linux; 

wKioL1kcdO3icCzxAACh7LJyioo373.png-wh_50

   (5)alter table linux drop exam; ####删除linux中的exam字段
        select * from linux; 

wKiom1kcdO7DzTzKAACSn8sFuz0563.png-wh_50

    (6)update linux set password=password('123')where ( username='user' or username='user1');
    ####更新两个用户的密码,并加密
     select * from linux; 
wKioL1kcdO7QeP5gAACwRGoPS-0699.png-wh_50


 5 数据库的备份
       2 mysqldump -u root -pqwer1234 --all-database
          ####备份所有表中的所有数据
       3 mysqldump -u root -pqwer1234 --all-database --no-data
          ####备份所有表,但不备份数据
       4 mysqldump -u root -pqwer1234 westos
          ####备份westos库 
       5 mysqldump -u root -pqwer1234 westos > /mnt/westos.sql
          ####备份westos库并把数据保存到/mnt/westos.sql
       8 mysql -uroot -pqwer1234 -e "create database westos;" 
          ####建立westos库
       9 mysql -u root -pqwer1234 westos < /mnt/westos.sql
          ####把数据导入westos库
      10 mysql -u root -pqwer1234
      16 mysqldump -u root -pqwer1234 westos linux > /mnt/linux.sql
           ####备份westos库中的linux表并把数据保存到/mnt/linux.sql
      17 mysqldump -u root -pqwer1234 westos test> /mnt/test.sql
          ####备份westos库中的test表并把数据保存到/mnt/test.sql
      27 mysql -u root -pqwer1234 -e "show tables from westos"
          ###显示westos库中表的名字
      28 mysql -u root -pqwer1234 westos < /mnt/test.sql
          ####把test表中数据导入westos库
      29 mysql -u root -pqwer1234 -e "show tables from westos"
          ###显示westos库中表的名字


wKiom1kcdRCRLMuOAADCs8E5cdI372.png-wh_50

wKioL1kcdRDyiuAyAACu5y1QZ8I674.png-wh_50

wKioL1kcdRHwg--cAABdo26OgX0941.png-wh_50


 6 数据库的删除
   (1) 删除表中数据  delete from linux where username='username';
       mysql -u root -pqwer1234
       MariaDB [(none)]> usewestos    ###进入westos库
       MariaDB [westos]> select * fromlinux;    ###查询linux表中的所有内容
        delete from linux whereusername='user1'; ###删除linux表中的user1的数据
        delete from linux whereusername='user'; ###删除linux表中的user的数据
        select * from linux; ###查询linux表中的所有内容

wKiom1kcdTKDOs0OAACv9db1E2s213.png-wh_50

   (2)删除表
        drop table linux;
   (3)删除库
        drop database westos;

wKiom1kcdTLi-TYzAAB_8OHKG4c357.png-wh_50

wKioL1kcdTLyPmgaAACa4Id1BjY362.png-wh_50



 7 用户授权 
  (1)建立用户 
     MariaDB [(none)]> create userlee@localhost identified by ' lee';
      ####建立用户lee本机登陆
     MariaDB [(none)]> create userlee@'%' identified by ' lee';
      ####建立lee用户,网络登陆

wKiom1kcdY_Tpw-jAAChx7kAt78753.png-wh_50

wKioL1kcdZDgJFOYAACoQLlqCO0405.png-wh_50


  (2)用户授权
     MariaDB [(none)]> grantinsert,update,delete,select on westos.test to lee@localhost;
       ### 本机登陆lee,授权
      MariaDB [(none)]> grant selecton westos.* to lee@'%' ; 
        ####网络登陆lee,授权

wKioL1kcdZDDIxKxAACwPpFHC5U562.png-wh_50

   (3)查看用户权力
      MariaDB [(none)]> show grantsfor lee@'%'
       ####查看用户权力
      MariaDB[(none)] > show grantsfor lee@localhost;、
       ####查看用户权力

   (4)去除用户授权权力
       MariaDB [(none)]> revoke deleteon westos.test from lee@localhost; 
       ######去除用户授权权力
       MariaDB [(none)]> show grantsfor lee@localhost; 查看权限

wKiom1kcdZHhiymxAAD5OqBJx7A148.png-wh_50

    (5)删除用户
         MariaDB [(none)]> selectUser,Host from mysql.user;查看用户
         MariaDB [(none)]]> drop userlee@'%'; 删除用户
         MariaDB [(none)]> selectUser,Host from mysql.user;查看用户wKiom1kcdZHDC5_OAACK84M0bLM664.png-wh_50


8  密码修改
  (1)超级用户密码知道
   mysqladmin -uroot -p234 password lee   ##修改超级用户密码为lee
  (2)超级用户密码忘记
   [root@mariadb mnt]# mysqld_safe--skip-grant-tables & 
    ####开启mysql登陆接口并忽略授权表
   [root@mariadb mnt]# mysql ###进入mysql
    MariaDB [(none)]> selectUser,Host,Password from mysql.user; 
    ####查看mysql.user中用户及用户密码
    MariaDB [(none)]> updatemysql.user set Password=password('234') where User='root';  ##更新超级用户密码信息为234
    MariaDB [(none)]> select User,Host,Passwordfrom mysql.user;
     ####查看mysql.user中用户及用户密码
    MariaDB [(none)]> quit
[root@mariadb mnt]# fg
[root@mariadb mnt]# killall -9 mysqld_safe ####关闭mysqld_safe进程
[root@mariadb mnt]# ps aux | grep mysql ###过滤mysql的所有进程
[root@mariadb mnt]# kill -9 mysqlpid    ####关闭mysql的所有进程
[root@mariadb mnt]# systemctl restart mariadb ###重启mariadb服务
[root@mariadb mnt]# mysql -uroot -p234 ###登陆测试

wKioL1kcdp_CbYuGAAB42rPX82A039.png-wh_50

wKiom1kcdqDjFlhaAAFTPW71E9w578.png-wh_50

wKioL1kcdqDwCkjTAAFLacDsX60364.png-wh_50

wKiom1kcdp-jXFuOAACILsi1d7A730.png-wh_50


 三 数据库的页管理工具
1.安装     
156 yum install httpd php php-mysql -y ##安装 httpd php php-mysql三个安装包
     yum install php-mysql.x86_64-y
     yum install httpd -y
     yum install php.x86_64 -y

157 systemctl start httpd.service              ##开启httpd服务
158 systemctl enable httpd 
159 systemctl stop firewalld.service              ##关闭火墙
160 systemctl disable firewalld 
2. 需要下载
162 phpMyAdmin-3.4.0-all-languages.tar.bz2 #### 压缩包
163 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html
    ####解压压缩包到/var/www/html
164 mv phpMyAdmin-3.4.0-all-languages/ mysqladmin
   #### 将安装包下的所有文件移动到 mysqladmin
165 cd mysqladmin
166 cp -p  config.sample.inc.phpconfig.inc.php ###复制配置文件
167 vim config.inc.php   ###写配置文件

  $cfg['blowfish_secret'] = 'mysql';/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

wKioL1kcde7B9kluAABcnfPSR9U187.png-wh_50

168 systemctl restart httpd 
3.测试
访问
173 http://172.25.254.144/mysqladmin

wKiom1kcde7inZBMAACPOkBPWyA544.png-wh_50

wKioL1kcde-i-h08AACnj2o4FSQ886.png-wh_50

wKiom1kcde-QqDBQAABiGX4nXog254.png-wh_50

wKiom1kcde-wZReDAABMFVll9ZA214.png-wh_50










本文转自 如何何如  51CTO博客,原文链接:http://blog.51cto.com/12778805/1926836,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3月前
|
网络协议 关系型数据库 MySQL
如何搭建MariaDB并实现无公网ip环境远程连接本地数据库
如何搭建MariaDB并实现无公网ip环境远程连接本地数据库
75 0
|
1月前
|
网络协议 关系型数据库 MySQL
如何实现在公网下使用navicat图形化工具远程连接本地内网的MariaDB数据库
如何实现在公网下使用navicat图形化工具远程连接本地内网的MariaDB数据库
|
1月前
|
网络协议 关系型数据库 MySQL
安卓手机termux上安装MariaDB数据库并实现公网环境下的远程连接
安卓手机termux上安装MariaDB数据库并实现公网环境下的远程连接
|
2月前
|
网络协议 关系型数据库 MySQL
通过内网穿透本地MariaDB数据库,实现在公网环境下使用navicat图形化工具
本篇教程将使用cpolar内网穿透本地MariaDB数据库,并实现在外公网环境下使用navicat图形化工具远程连接本地内网的MariaDB数据库。
|
3月前
|
网络协议 关系型数据库 MySQL
如何使用navicat图形化工具远程连接MariaDB数据库【cpolar内网穿透】
如何使用navicat图形化工具远程连接MariaDB数据库【cpolar内网穿透】
78 0
|
6月前
|
NoSQL 关系型数据库 MySQL
阿里云关系型数据库详细介绍MySQL/MariaDB/SQL Server/PolarDB/PostgreSQL等
阿里云关系型数据库详细介绍MySQL/MariaDB/SQL Server/PolarDB/PostgreSQL等,阿里云RDS关系型数据库如MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
114 0
|
6月前
|
NoSQL Cloud Native 关系型数据库
阿里云RDS数据库_MySQL_SQL Server_MariaDB_PolarDB_PostgreSQL
阿里云RDS关系型数据库大全:MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
110 0
|
16天前
|
SQL 数据可视化 关系型数据库
轻松入门MySQL:深入探究MySQL的ER模型,数据库设计的利器与挑战(22)
轻松入门MySQL:深入探究MySQL的ER模型,数据库设计的利器与挑战(22)
|
16天前
|
存储 关系型数据库 MySQL
轻松入门MySQL:数据库设计之范式规范,优化企业管理系统效率(21)
轻松入门MySQL:数据库设计之范式规范,优化企业管理系统效率(21)
|
16天前
|
关系型数据库 MySQL 数据库
轻松入门MySQL:精准查询,巧用WHERE与HAVING,数据库查询如虎添翼(7)
轻松入门MySQL:精准查询,巧用WHERE与HAVING,数据库查询如虎添翼(7)

推荐镜像

更多