• CentOS7 安装MariaDB


          MariaDB数据库管理系统是MySQL的一个分支。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。一些如谷歌、维基、LinkedIn、Mozilla等的顶级的网站已经迁移到MariaDB了

      安装MySQL,发现是CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替。毫不客气,折腾小海狮。

      系统环境:

    [root@lxd ~]# cat /etc/redhat-release 
    CentOS Linux release 7.0.1406 (Core) 
    

      安装mariadb server和客户端:

    [root@lxd ~]# yum install mariadb-server mariadb
    

      等待安装完成即可。开启mariadb server,并设置开机自启动。

    [root@lxd ~]# systemctl start mariadb.service
    [root@lxd ~]# systemctl enable mariadb.service
    ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
    

      MariaDB Server预设root密码为空,重设root密码有两种方法,一种是传统方法,登入mysql修改密码,一种是用mysql_secure_installation。

      方法1:

      登入mariadb,进入mysql数据库,更新密码

     

    [root@lxd ~]# mysql -u root
    MariaDB [(none)]> use mysql;
    MariaDB [mysql]> update user set password=PASSWORD(“密码写在这”) where User=’root’;

         需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问。quit退出,重新登入。

    MariaDB [mysql]> flush privileges;
    
    MariaDB [mysql]> quit
    使用新密码重新登入
    [root@lxd ~]# mysql -u root -p
    

     方法2:

    [root@lxd ~]# mysql_secure_installation
    /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none): //密码为空,直接回车
    OK, successfully used password, moving on...
    
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    
    Set root password? [Y/n] y     //是否设置root密码
    New password: 
    Re-enter new password: 
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] y    //清楚匿名用户
     ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] n   //不允许root远程连接
     ... skipping.
    
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] y  //删除test数据库
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] y  //重新加载权限表
     ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!
    

      OK,现在重新进入

    [root@lxd ~]# mysql -u root -p 
    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 12
    Server version: 5.5.44-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    MariaDB [(none)]> 
    

      还有重要的一步,设置允许远程用户访问。

    MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    

      "%"表示任何主机都可以远程登录到该服务器上访问。如果要限制只有某台机器可以访问,将其换成相应的IP即可

         开启3306端口。centos7启用了firewalld替代了原来的iptables。既然新事物出现,一定有它出现的理由。

    [root@lxd ~]# systemctl start firewalld                    //启动firewalld服务
    [root@lxd ~]# firewall-cmd --state
    running

    [root@lxd ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent    //开启端口

    success

    [root@lxd ~]# firewall-cmd --reload
    success

    命令含义:
     
    --zone #作用域
     
    --add-port=3306/tcp  #添加端口,格式为:端口/通讯协议
     
    --permanent   #永久生效,没有此参数重启后失效
     
    重启防火墙
    

    确认一下开启了端口:

    [root@lxd ~]# netstat -ntlp | grep 3306
    tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2911/mysqld         
    

     

    BINGO!继续折腾

  • 相关阅读:
    JAVA FTP 客户端 .
    附件上传byte2hex二行制转字符串优化方法
    JSTL的c:forEach标签(${status.index})
    jco 连接池
    FOWARD和response.sendRedirect()区别
    Windows BAT命令编写大全
    SQLServer 触发器详解
    区分ff/ie6/ie7/ie8,解决样式不兼容
    android在学习——程序的退出
    关于struts2 获取页面表单信息的个人做法
  • 原文地址:https://www.cnblogs.com/XYJK1002/p/4877525.html
Copyright © 2020-2023  润新知