安装MariaDB

yum安装:
yum groupinstall mariadb mariadb-client
其中mariadb包组为服务,包含以下安装包:
mariadb-server: mandatory package
mariadb-bench: optional package
mariadb-test: optional package
其中mariadb-client为客户连接端
Mariadb: mandatory package
MySQL-python: default package
mysql-connector-odbc: default package
libdbi-dbd-mysql: optional package
mysql-connector-java: optional package
perl-DBD-MySQL: optional package
设置开机启动
systemctl start mariadb
systemctl enable mariadb
设置数据库安全性:
/usr/bin/mysql_secure_installation
交互界面
设置数据库管理员root口令
禁止root远程登录
删除anonymous用户帐号
删除test数据库
/usr/bin/mysql_secure_installation:行379: find_mysql_client: 未找到命令

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] n 是否删除测试数据库
… skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 配置是否生效
… 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!

编译完成的二进制包安装:
创建用户账户:
mariadb在运行时会以mariadb身份运行。
groupadd -r -g 27 mysql
useradd -r -g 27 -u 27 -d /data -s /sbin/nologin mysql
准备数据目录
mkdir /data
chown mysql.mysql /data
准备二进制程序:
tar -xvf mariadb***.tar.gz -C /usr/local
cd /usr/local ;ln -sv mariadb*** ./mysql (将解压出来的文件夹创建一个软连接为mysql,因为安装时需要用到的文件名称为mysql)
chown -R root.mysql /usr/local/mysql注:改变软连接的权限
chown-R root.mysql /usr/local/mysql/ 注:mysql改变的是软连接需要加/
创建配置文件:
注:配置文件查找路径为:后面的配置会覆盖前面相同的配置。
/etc/my.cnf
/etc/mysql/my.cnf
–default-extrafile=/PATH/TO/CONF_FILE
~/.my.cnf
mkdir /etc/mysql/
cp -p /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf
更改配置文件:vim /etc/mysql/my.cnf
[mysqld]中添加三个选项:
datadir = /data
innodb_file_per_table = on采用innodb数据引擎,每个表单独为一个文件
skip_name_resolve = on 禁止主机名解析
创建数据库文件
/usr/local/mysql/scripts/mysql_install_db –help显示帮助信息
cd /usr/local/mysql/;./scripts/mysql_install_db–datadir=/data –user=mysql
此命令只能在mysql文件夹下运行,使用全路径运行./mysql_install_db运行都会出错
准备日志文件
日志在/etc/my.cnf文件中定义,log-error=/var/log/mysqld.log。
touch /var/log/mysqld.log
chown mysqld /var/log/mysqld.log
准备服务脚本,并启动服务
cd /usr/local/mysql/ ;cp ./support-files/mysql.server/etc/rc.d/init.d/mysqld
chkconfig –add mysqld
service mysqld start
安全初始化
/user/local/mysql/bin/mysql_secure_installation
连接器地址位于:/user/local/mysql/bin/mysql
添加环境变量:
vim/etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:${PATH}

### 如何安装 MariaDB #### 1. 使用 Yum 安装 MariaDB 对于基于 Red Hat 的系统(如 CentOS 或 RockLinux),可以通过 `yum` 包管理器来安装 MariaDB。以下是具体操作: - **添加 MariaDB 源** 可以通过运行官方提供的脚本来自动配置 MariaDB 的源[^1]。 ```bash sudo yum install wget -y wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup chmod +x mariadb_repo_setup ./mariadb_repo_setup --mariadb-server-version="11.0" ``` - **更新并安装 MariaDB** 执行以下命令以安装 MariaDB: ```bash sudo yum update -y sudo yum install MariaDB-server MariaDB-client -y ``` #### 2. 启动服务并设置开机自启 安装完成后,启动 MariaDB 并将其设为随系统启动而运行: ```bash sudo systemctl start mariadb sudo systemctl enable mariadb ``` 验证服务状态可以执行以下命令: ```bash sudo systemctl status mariadb ``` 如果一切正常,则会显示 MariaDB 正在运行的状态。 #### 3. 登录到 MariaDB 控制台 首次登录时,默认情况下 root 用户密码为空。可以直接输入以下命令进入控制台: ```bash mysql -u root -p ``` 随后按照提示输入密码即可访问数据库环境[^2]。 #### 4. 配置安全选项 为了提高安全性,建议运行内置的安全脚本: ```bash sudo mysql_secure_installation ``` 此工具可以帮助您设置 root 密码、删除匿名用户、禁用远程 root 访问以及移除测试数据库等。 --- ### 替代方案:手动配置 Yum 源 如果您不希望使用官方脚本,也可以手动编辑 `/etc/yum.repos.d/` 下的 `.repo` 文件来指定 MariaDB 的仓库地址。例如: - **官方源配置示例** ```ini [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/11.0/centos7-amd64 gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck = 1 enabled = 1 ``` - **阿里云镜像源配置示例** 如果网络条件不佳或者需要更快的速度,可以选择国内的阿里云镜像源: ```ini [mariadb] name = MariaDB baseurl = https://mirrors.aliyun.com/mariadb/yum/11.0/centos7-amd64/ gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1 enabled = 1 ``` 保存文件后重新加载缓存数据: ```bash sudo yum makecache fast ``` 之后继续按前述步骤完成安装过程[^3]。 --- ### 离线安装方式 当目标机器无法连接互联网时,可采用离线方式进行安装。首先下载对应版本的二进制包至本地服务器或其他有网设备上,再传输给无网主机解压部署。通常做法如下所示: 1. 解压缩已获取的 tarball 文件; ```bash tar xf mariadb-*.tar.gz -C /usr/local/mysql ``` 2. 创建必要的符号链接以便于后续维护工作顺利开展; ```bash ln -s /usr/local/mariadb-* /usr/local/mysql ``` 注意这里假设最终路径应指向标准位置即 `/usr/local/mysql`[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值