linux安装MariaDB教程

2021-08-05由程序员日记发表于系统教程 浏览39次

转载(https://blog.csdn.net/ownbull/article/details/80460857

一、下载MariaDB
wget https://downloads.mariadb.com/MariaDB/mariadb-10.3.7/bintar-linux-glibc_214-x86_64/mariadb-10.3.7-linux-glibc_214-x86_64.tar.gz

二、安装MariaDB

  1. 准备
    (1)解压tar.gz文件
    tar -zxvf mariadb-10.3.7-linux-glibc_214-x86_64.tar.gz
    (2)将解压后的文件夹移动至 /usr/local 文件夹下
    mv mariadb-10.3.7-linux-glibc_214-x86_64 /usr/local
    (3)切换工作目录至 /usr/local
    cd /usr/local
    (4)创建文件链接mysql
    ln -s mariadb-10.3.7-linux-glibc_214-x86_64 mysql
    (5)创建mysql用户组及用户
    groupadd mysql
    useradd -g mysql mysql

创建数据目录
mkdir /home/mysql/data

  1. 安装配置
    (1)执行配置脚本
    cd mysql
    ./scripts/mysql_install_db --user=mysql --datadir=/home/mysql/data
    (2)更改文件及文件夹权限
    chown -R root:mysql .
    chown -R mysql:mysql data

修改/etc/my.cnf中的配置
datadir = /app/dbdata
innodb_file_per_table = on
skip_name_resolve = on

查看my.cnf下面几个文件路径,创建它并将权限赋给mysql用户与用户组
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

mkdir /var/log/mariadb
mkdir /var/run/mariadb
touch /var/log/mariadb/mariadb.log
touch /var/run/mariadb/mariadb.pid
chown -R mysql:mysql /var/run/mariadb
chown -R mysql:mysql /var/log/mariadb
3. 启动数据库
./bin/mysqld_safe --user=mysql --datadir=/home/mysql/data &

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

  1. 设置数据库root用户密码
    (1)设置root用户密码
    ./bin/mysqladmin -u root password ‘123456’
    (2)查看主机名
    [[email protected] mysql]# hostname
    ecs-test1.novalocal
    (3)设置连接到本主机的root用户密码
    ./bin/mysqladmin -u root -h localhost.localdomain password ‘123456’
  2. 关闭数据库
    [[email protected] mysql]# ./bin/mysqladmin -uroot -p shutdown
    Enter password:
    [1]+ Done ./bin/mysqld_safe --user=mysql

四、数据库连接、查询

  1. 连接与登录
    [[email protected] mysql]# ./bin/mysql -uroot -p
    Enter password:
  2. 查询
    MariaDB [(none)]> show databases;
    MariaDB [(none)]> use mysql;
    MariaDB [mysql]> desc user;
    MariaDB [mysql]> select host,user,password from user;