zoukankan      html  css  js  c++  java
  • 在Linux上用rpm 安装及配置MariaDB

    安装MariaDB

    1.切换到root用户,首先执行rpm -qa | grep -i mysql检查一下是否有已安装的与MySQL相关的东西,如果有,使用rpm -e --nodeps mysql*进行强制卸载

    2.使用yum安装MariaDB,执行yum -y install mariadb mariadb-server

    3.安装完成后,执行systemctl start mariadb 启动MariaDB,执行systemctl enable mariadb设置开机启动

    配置MariaDB

    1.执行mysql_secure_installation进行相关配置 
    - 首先是设置密码,会提示先输入密码: 
    * Enter current password for root (enter for none):<–初次运行直接回车 
    - 设置密码 
    * Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车 
    * New password: <– 设置root用户的密码 
    * Re-enter new password: <– 再输入一次你设置的密码 
    - 其它配置 
    * Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车 
    * Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车, 
    * Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车 
    * Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

    2.配置完成后,执行mysql -uroot -ppassword测试登录。其中root为要登录的用户名,password为刚才设置的root用户的密码

    3.测试成功后,配置MariaDB的字符集 
    - 使用vi编辑器打开/etc/my.cnf,在[mysqld]中添加

    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编辑器打开/etc/my.cnf.d/client.cnf,在[client]中添加 
      default-character-set=utf8
    • 使用vi编辑器打开/etc/my.cnf.d/mysql-clients.cnf,在[mysql]中添加 
      default-character-set=utf8
    • 全部保存后,进入到MariaDB控制台,查看字符集 
      show variables like "%character%";show variables like "%collation%"; 
      全部显示UTF-8则配置成功

    配置MariaDB远程连接

    进入到MariaDB控制台 
    1.执行如下语句建立用户并赋予所有操作权限。 
    CREATE USER 'username'@'host' IDENTIFIED BY 'password';

    参数说明
    username 将要创建的用户名
    host 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%
    password 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器

    2.给用户赋予远程登录权限 
    GRANT privileges ON databasename.tablename TO 'username'@'host'

    参数说明
    privileges 用户的操作权限,如SELECT , INSERT , UPDATE 等(权限列表见文末)。如果要授予所的权限则使用ALL
    databasename 数据库名
    tablename 表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示,如.*

    3.修改完成后在MariaDB控制台执行FLUSH PRIVILEGES刷新配置权限使其生效

    此时即可通过ip远程访问主机上的MariaDB了。

    若仍不能访问,可进行以下检查: 
    1.查看/etc/my.cnf,如skip-networking、bind-address(或bindaddress)被配置,则需要将这两个参数注释掉。

    skip-networking 这个参数,会导致所有TCP/IP端口没有被监听,也就是说除了本机,其他客户端都无法用网络连接到本MariaDB服务器。 
    而bind-address这个参数是指定哪些ip地址被配置,使得MariaDB服务器只回应哪些ip地址的请求

    2.如果仍然不能访问,则有可能是防火墙的原因。在shell下执行/etc/init.d/iptables  stop关闭防火墙。

    附:MariaDB操作权限

    权限描述
    ALTER Allows use of ALTER TABLE
    ALTER ROUTINE Alters or drops stored routines
    CREATE Allows user of CREATE TABLE
    CREATE ROUTINE Creates stored routines
    CREATE TEMPORARY TABLE Allows user of CREATE TEMPORARY TABLE
    CREATE USER Allows use ofCREATE USER,DROP USER,RENAME USER, and REVOKE ALL PRIVILEGES
    CREATE VIEW Allows use of CREATE VIEW
    DELETE Allows use of DELETE
    DROP Allows use of DROP TABLE
    EXECUTE Allows the user to run stored routines
    FILE Allows use of SELECT...INTO OUTFILE and LOAD DATA INFILE
    INDEX Allows use of CREATE INDEX and DROP INDEX
    INSERT Allows use of INSERT
    LOCK TABLES Allows use of LOCK TABLES on tables for which the user also has SELECT privileges
    PROCESS Allows use of `SHOW FULL PROCESSLIST
    RELOAD Allows use of FLUSH
    REPLICATION Allows the user to ask where slave or master
    CLIENT servers are
    REPLICATION SLAVE Needed for replication slaves
    SELECT Allows use of SELECT
    SHOW DATABASES Allows use of SHOW DATABASE
    SHOW VIEW Allows use of SHOW CREATE VIEW
    SHUTDOWN Allows use of mysqladmin shutdown
    SUPER Allows use of CHANGE MASTER,KILL,PURGE MASTER LOGS,andSET GLOBAL SQL statements. Allowsmysqladmin debug command.Allows one extra connection to be made if maximum connections are reached.
    UPDATE Allows use of UPDATE
    USAGE Allows connection without any specific privileges

    systemctl start mariadb #启动服务 systemctl enable mariadb #设置开机启动 systemctl restart mariadb #重新启动 systemctl stop mariadb.service #停止MariaDB
  • 相关阅读:
    python-阿里镜像源-pip
    python-Web-django-图形验证
    markdown-博客编辑
    python-爬虫-史书典籍
    python-爬虫-requests
    python-Web-项目-svn和git
    python-Web-数据库-Redis
    Codeforces Round #617 (Div. 3) A~D
    Educational Codeforces Round 81 (Rated for Div. 2)
    Codeforces Round #609 (Div. 2) A到C题
  • 原文地址:https://www.cnblogs.com/bug1024/p/8920605.html
Copyright © 2011-2022 走看看