Linux 下离线安装 MariaDB

  1. 下载 MariaDB 安装包

    下载地址: https://downloads.mariadb.org/

  2. 卸载系统自带的mysql
    #检查mariadb是否存在
    [root@cdh01 local]# rpm -qa | grep mariadb
    mariadb-libs-5.5.60-1.el7_5.x86_64
    #卸载
    [root@cdh01 local]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
    [root@cdh01 local]# find / -name mysql
    /var/lib/pcp/config/pmlogconf/mysql
    /usr/lib64/mysql
    /usr/share/mysql
    [root@cdh01 local]# rm -rf /var/lib/pcp/config/pmlogconf/mysql
    # 手动删除  数据库目录
    [root@cdh01 local]# rm -rf /var/lib/mysql/
    # 手动删除  数据库配置文件
    [root@cdh01 local]# rm -rf /usr/share/mysql/
    
  3. 解压 MariaDB 安装包
    [root@cdh01 local]# tar -zxvf mariadb-10.4.11-linux-x86_64.tar.gz
    [root@cdh01 local]# ln -s mariadb-10.4.11-linux-x86_64.tar.gz mariadb
    
  4. 创建 mysql 用户及用户组并更改所属的组和用户
    [root@cdh01 local]# groupadd mysql
    [root@cdh01 local]# useradd -g mysql mysql
    [root@cdh01 local]# chown -R mysql:mysql mariadb/
    
  5. 新建配置文件my.cnf

    新建配置文件 /etc/my.cnf,并添加以下配置

    [mysql]
    #设置mysql客户端默认字符集
    default-character-set=utf8 
    [mysqld]
    skip-name-resolve
    #设置3306端口
    port = 3306 
    #设置mysql的安装目录
    basedir=/usr/local/mariadb
    #设置mysql数据库的数据的存放目录
    datadir=/usr/local/mariadb/data
    #允许最大连接数
    max_connections=200
    #服务端使用的字符集默认为8比特编码的latin1字符集
    character-set-server=utf8
    #创建新表时将使用的默认存储引擎
    default-storage-engine=INNODB 
    lower_case_table_names=1
    max_allowed_packet=16M
    
  6. 安装 MariaDB 并初始化
    [root@cdh01 mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/data
    Installing MariaDB/MySQL system tables in '/usr/local/mariadb/data' ...
    OK
    
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system
    ...
    

    参考: https://mariadb.com/kb/en/library/mysql_install_db/

  1. 创建mysqld
    [root@cdh01 mariadb]# cp ./support-files/mysql.server /etc/init.d/mysqld
    [root@cdh01 mariadb]# ll /etc/init.d/mysqld
    -rwxr-xr-x 1 root root 12245 Dec 19 13:46 /etc/init.d/mysqld   # 是否可执行
    
  2. 设置为开机启动
    [root@cdh01 mariadb]# chkconfig --list mysqld
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld')
    # 添加到系统服务 chkconfig
    [root@cdh01 mariadb]# chkconfig --add mysqld
    [root@cdh01 mariadb]# chkconfig --list mysqld
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    mysqld           0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@cdh01 mariadb]# service mysqld restart
    Restarting mysqld (via systemctl):                         [  OK  ]
    
  1. 配置环境变量
    [root@cdh01 mariadb]# vim /etc/profile
    
    #set mariadb environment
    export MARIADB_HOME=/usr/local/mariadb
    export PATH=$PATH:${MARIADB_HOME}/bin
    
    [root@cdh01 mariadb]# source /etc/profile  
    
  2. 配置 MariaDB
    # -bash: ./bin/mariadb-secure-installation: No such file or directory
    # 报上述问题,请使用 ./bin/mysql_secure_installation
    [root@cdh01 mariadb]# ./bin/mariadb-secure-installation --basedir=/usr/local/mariadb
    print: /usr/local/mariadb/bin/my_print_defaults
    
    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] Y
    Enabled successfully!
    Reloading privilege tables..
     ... Success!
    
    
    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] n
     ... 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
     - 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!
    
  3. 授权远程连接
    [root@DSJ-TVM002 mariadb]# mysql -u root -p
    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 10
    Server version: 10.4.11-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by "123456" with grant option;
    Query OK, 0 rows affected (0.003 sec)
    
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.000 sec)
    

    如未授权访问,使用 Navicat 连接时可能遇到如下提示

    image

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,186评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,858评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,620评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,888评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,009评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,149评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,204评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,956评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,385评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,698评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,863评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,544评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,185评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,899评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,141评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,684评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,750评论 2 351

推荐阅读更多精彩内容