站点刚更新,有问题请联系QQ 2535458415

CentOS7.3安装MariaDB

编程 王苗森 3202℃ 0评论

CentOS7.3安装MariaDB

  1. https://downloads.mariadb.org/mariadb/+releases/ 中找到MariaDB最新稳定版本,目前最新稳定版是10.4.12
  2. 点击进入后,切换软件源为清华大学的国内源。
  3. 点击
  4. 选择 centos73-amd64/,并复制链接
  5. 打开https://mariadb.com/kb/en/yum/,找到
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.3/centos7-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    

将刚才复制的链接替换baseurl,并将gpgcheck改为0
6. 终端键入vi /etc/yum.repos.d/MariaDB.repo,将改好的配置文件粘贴到其中,保存修改。
7. 执行yum install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common
8. 启动MariaDBservice mariadb start
9. 初始化mysql_secure_installation
10. 配置

    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
    haven't set the root password yet, you should just press enter here.

    Enter current password for root (enter for none): (默认密码没有)
    OK, successfully used password, moving on...

    Setting the root password or using the unix_socket ensures that nobody
    can log into the MariaDB root user without the proper authorisation.

    You already have your root account protected, so you can safely answer 'n'.

    Switch to unix_socket authentication [Y/n] n(不使用unix_socket)
    ... skipping.

    You already have your root account protected, so you can safely answer 'n'.

    Change the root password? [Y/n] y
    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] y
    ... Success!

    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
    - 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!
  1. 新增一个远程管理用户
    • mysql -uroot -p
    • 输入刚才设置的root密码
    • use mysql
    • CREATE USER '新用户名'@'%' IDENTIFIED BY '新密码'; 其中%代表可以让任何ip登录
  2. 创建新数据库
    • CREATE DATABASE `medblog`;
    • 授权 grant all privileges on medblog.* to 新用户名@'%';
    • 取消授权 revoke all on medblog.* from 新用户名@'%';
    • 刷新 flush privileges;
  3. 配置文件
    • cd /etc/my.cnf.d/
    • vi client.cnf
      [client]
      port = 2295
      default-character-set=utf8
      
    • vi server.cnf
      [mysqld]
      lower_case_table_names = 1
      port = 2295
      init_connect='SET collation_connection = utf8_unicode_ci'
      init_connect='SET NAMES utf8'
      character-set-server=utf8
      collation-server=utf8_unicode_ci
      skip-character-set-client-handshake
      
    • vi mysql-clients.cnf
      [mysql]
      default-character-set=utf8
      
    • 重新启动 service mariadb restart
      14.开放2295端口
      编辑public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <rule family="ipv4">
    <source address="0.0.0.0/0"/>
    <port protocol="tcp" port="2295"/>
    <accept/>
  </rule>
</zone>

上传到/etc/firewalld/zones;执行firewall-cmd --reload

转载请注明:医学园地 » CentOS7.3安装MariaDB

喜欢 (4)

您必须 登录 才能发表评论!