## 二进制安装
1、删除centos系统自带的mariadb数据库
```shell
[root@localhost local]# rpm -qa |grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost local]# rpm -e mariadb-libs-5.5.68-1.el7.x86_64
错误:依赖检测失败:
libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要
#需要删除相应的依赖
[root@localhost local]# rpm -e postfix-2:2.10.1-9.el7.x86_64
#再次执行
[root@localhost local]# rpm -e mariadb-libs-5.5.68-1.el7.x86_64
#或者执行
[root@localhost local]yum remove mariadb-libs-5.5.68-1.el7.x86_64
```
2、安装<font color='pink'>libaio</font>库
```shell
yum install libaio
```
3、解压数据数据库文件
```shell
tar -xzvf mysql-5.7.35-el7-x86_64.tar.gz
```
4、创建msyql用户和组并设置为非登录用户
```shell
groupadd mysql
useradd -r -g mysql mysql -s /bin/false
```
5、创建链接文件,datadir目录
```shell
[root@db3]# mkdir -p /data/3306/data
[root@db3]# chown -hR mysql.mysql /data
[root@db3]# ln -s /opt/mysql-5.7.35-el7-x86_64 /usr/local/mysql
```
6、创建日志、socket文件并给定权限
```shell
touch /var/log/mysqld.log
chown mysql:mysql /var/log/mysqld.log
touch /data/3306/mysql.sock
chown mysql:mysql /data/3306/mysql.sock
```
7、创建my.cnf配置文件
```shell
[mysqld]
character-set-server=utf8
user=mysql
port=3306
basedir=/data/3306/
datadir=/data/3306/data
socket=/tmp/mysql.sock
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/data/3306/mysql.pid
[client]
port=3306
socket=/tmp/mysql.sock
```
8、添加环境变量并使之生效
```shell
export PATH=$PATH:/data/3306/bin
source /etc/profile
```
9、安装数据库初始化
```shell
[root@db3 data]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
2022-03-29T03:20:48.883293Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-03-29T03:20:49.147461Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-03-29T03:20:49.228807Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-03-29T03:20:49.303679Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3b2114a3-af0f-11ec-a391-005056935e71.
2022-03-29T03:20:49.305532Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-03-29T03:20:50.006143Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-03-29T03:20:50.006161Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-03-29T03:20:50.006775Z 0 [Warning] CA certificate ca.pem is self signed.
2022-03-29T03:20:50.122341Z 1 [Note] A temporary password is generated for root@localhost: J/MgcJ0?q1i! #初始密码
```
10、第一次启动数据库
```shell
mysqld_safe &
```
11、设置开机自启动
```shell
#复制启动脚本到资源目录中
cp /data/3306/support-files/mysql.server /etc/rc.d/init.d/mysqld
#将msyqld加入到系统启动服务
chkconfig --add mysqld
#查看mysqld是否加入
chkconfig --list mysqld
```
12、启动并登录到mysql中
```shell
mysql -uroot -p #将初始密码输入到此
```
13、变更初始密码
```mysql
alter user root@localhost identified by 'leadchina';
flush privileges; #可以省略
```
14、添加远程账户
```mysql
grant all privileges on *.* to root@'%' identified by 'leadchina' with grant option;
flush privileges;
```
15、开启防火墙端口