二进制安装mariadb10.2.44
安装前的准备:
1. yum info mariadb,找到mariadb-10.2.44-linux-glibc_214-x86_64.tar.gz版本下载。
安装步骤:
1、安装相关依赖包
[root@centos7 ~]#yum -y install libaio numactl-libs
2、创建用户和组
[root@centos7 ~]#groupadd mysql
[root@centos7 ~]#useradd -r -g mysql -s /bin/false mysql
3、准备程序文件
[root@centos7 ~]#tar xfv mariadb-10.2.44-linux-glibc_214-x86_64.tar.gz -C /usr/local
[root@centos7 ~]#cd /usr/local/
[root@centos7 local]#ln -sv mariadb-10.2.44-linux-glibc_214-x86_64 mysql
[root@centos7 local]#chown -R root.root /usr/local/mysql/
4、准备环境变量
[root@centos7 local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos7 local]#. /etc/profile.d/mysql.sh
5、创建数据库目录,修改权限
[root@centos7 local]#mkdir -pv /data/mysql
[root@centos7 local]#chown -R mysql:mysql /data/mysql/
6、准备配置文件
[root@centos7 local]#cd /usr/local/mysql/
[root@centos7 mysql]#cp /etc/my.cnf{,.bak}
[root@centos7 mysql]#vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/data/mysql/mysql.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
7、创建配置文件中指定的路径并修改权限
[root@centos7 mysql]#mkdir /var/lib/mysql
[root@centos7 mysql]#chown -R mysql:mysql /var/lib/mysql/
[root@centos7 mysql]#touch /var/lib/mysql/mysql.sock
[root@centos7 mysql]#chmod guo+wr /var/lib/mysql/mysql.sock
[root@centos7 mysql]#ll /var/lib/mysql
[root@centos7 mysql]#touch /data/mysql/mysql.log
[root@centos7 mysql]#chmod guo+rw /data/mysql/mysql.log
[root@centos7 mysql]#ll /data/mysql/mysql.log
[root@centos7 mysql]#mkdir /var/run/mariadb
[root@centos7 mysql]#chown -R mysql:mysql /var/run/mariadb/
[root@centos7 mysql]#touch /var/run/mariadb/mariadb.pid
[root@centos7 mysql]#chmod guo+rw /var/run/mariadb/mariadb.pid
[root@centos7 mysql]#ll /var/run/mariadb/
8、初始化数据库文件并生成 root 空密码
[root@centos7 mysql]#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql &
9、启动MariaDB守护程序
[root@centos7 mysql]#./bin/mysqld_safe --user=mysql --datadir=/data/mysql &
10、准备服务脚本和启动
[root@centos7 mysql]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos7 mysql]#chkconfig --add mysqld
[root@centos7 mysql]#chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@centos7 mysql]#systemctl start mysqld.service
11、数据库的登录、查询,修改密码,Ctrl+D,退出数据库
[root@centos7 mysql]#ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@centos7 mysql]#./bin/mysql -uroot -p
MariaDB [(none)]> show databases;
MariaDB [(none)]> use mysql;
MariaDB [mysql]> select user,host,password from user;
MariaDB [mysql]> select VERSION();
+-----------------+
| VERSION() |
+-----------------+
| 10.2.44-MariaDB |
+-----------------+
1 row in set (0.00 sec)
MariaDB [mysql]> grant all privileges on *.* to root@'localhost'identified by "Mmagedu0!";
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> quit;
Bye
13、登录测试
[root@centos7 mysql]# mysql -uroot -pMmagedu0!
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.44-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)]>
14、加固MySQL服务器,在安装完成后,运行mysql_secure_installation命令,提高安全性
运行脚本:mysql_secure_installation
[root@centos7 mysql]# 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):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
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.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] y
...