yum安装Mariadb
设置Mariadb的yum源
vim /etc/yum.repos.d/mariadb.repo
[mariadb]
name=mariadb
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgcheck=0
使用清华yum源安装Mariadb,可以选择不同的版本,此处安装10.2.23 yum install mariadb-server
二进制安装Mariadb
1 准备mysql用户和组
groupadd -r -g 336 mysql #创建mysql组
useradd -r -g mysql -u 336 -s /sbin/nologin -d /data/mysql mysql #创建mysql用户,并加入mysql用户组,设置UID为336,设置默认shell为nologoin,家目录为/data/mysql 但不自动创建
2 准备二进制程序文件和相关文件属性
tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local #只能放在此目录中
cd /usr/local/
ln -s mariadb-10.2.23-linux-x86_64/ mysql #建立软件链接,方便使用
chown -R root.root /usr/local/mysql/ #设置属主和属组为root用户和root组
3 PATH变量
vim /etc/profile.d/mysql.sh
PATH=/usr/local/mysql/bin:$PATH
. /etc/profile.d/mysql.sh
4 准备数据库数据目录和数据(使用逻辑卷)
创建逻辑卷
pvcreate /dev/sda6
创建卷组
vgcreate vg0 /dev/sda6
创建逻辑卷
lvcreate -n mysql -L 20G /dev/vg0
创建文件系统并挂载到/data/mysql
mkfs.xfs /dev/vg0/mysql
mkdir /data/mysql
mount /dev/vg0/mysql /data/mysql
chown mysql.mysql /data/mysql/
cd /usr/local/mysql
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql #安装mysql到/data/mysql目录下,用户为mysql
5 准备Mysql的服务器端配置文件
mkdir /etc/mysql
cp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]
datadir=/data/mysql #设置目录为/data/mysql
6 准备服务启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
systemctl start mysqld
7 安全加固
[[email protected] ~]#/usr/bin/mysql_secure_installation
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] y #禁止root远程登录
... 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 #删除测试数据库test
- 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!
8 测试连接
mysql -uroot -pPASSWORD
原文地址:https://blog.51cto.com/13749470/2385769
时间: 2024-10-31 18:25:33