博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

linux二进制安装MariaDB

Posted on 2018-05-08 23:00  moss_tan_jun  阅读(266)  评论(0编辑  收藏  举报

第一步:准备账号

[root@centos7 ~]#getent passwd mysql //查看有没有mysql账号(没有的话需要创建)

[root@centos7 ~]#useradd -r mysql -s /sbin/nologin //创建系统账号 shell类型为nologin

[root@centos7 ~]#getent passwd mysql              
mysql:x:988:983::/home/mysql:/sbin/nologin
[root@centos7 ~]#id mysql
uid=988(mysql) gid=983(mysql) groups=983(mysql)

 

第二步:解压缩包

1.解压缩包
[root@centos7 ~]#tar xf mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local/  //解压路径必须的/usr/local/

[root@centos7 ~]#cd /usr/local/;ls
bin  games lib libexec sbin src etc  include  lib64  mariadb-10.2.12-linux-x86_64  share
2.创建软连接
[root@centos7 local]#ln -s mariadb-10.2.12-linux-x86_64/ mysql //建议给mariadb-10.2.12-linux-x86_64/ 加上软连接必须是mysql或者此文件改名为mysql
3.修改权限问题
[root@centos7 local]#cd mysql/
[root@centos7 mysql]#ll  
drwxrwxr-x  2 1021 zhang1  4096 Nov 14 22:34 bin
-rw-r--r--  1 1021 zhang1 17987 Jan  3 21:48 COPYING
················· 
解决如下
[root@centos7 local]#chown -R mysql.mysql mysql/
[root@centos7 local]#ll mysql/
drwxrwxr-x  2 mysql mysql  4096 Nov 14 22:34 bin
-rw-r--r--  1 mysql mysql 17987 Jan  3 21:48 COPYING
················· 
4.添加PATH
[root@centos7 bin]#echo 'PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
[root@centos7 bin]#cat /etc/profile.d/mysql.sh
PATH=/usr/local/mysql/bin:$PATH
[root@centos7 bin]#. /etc/profile.d/mysql.sh

 

第三步:数据库目录存放路径

考虑数据一直在增加建议放到逻辑卷中;下面开始创建逻辑卷
创建逻辑卷不懂得可以看前面文章查看怎么创建逻辑卷
[root@centos7 /]#blkid 
/dev/sda6: UUID="eeDr4z-UEpo-t6K6-BzAB-IwfG-1rhK-iTHhbx" TYPE="LVM2_member" 
/dev/mapper/vg0-lv_mysqldata: UUID="f1fab2a8-24f6-4752-b0ae-62b35f205f27" TYPE="xfs" 

[root@centos7 /]#lsblk
NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                    8:0    0  200G  0 disk 
······
└─sda6                 8:6    0   50G  0 part 
  └─vg0-lv_mysqldata 253:0    0   50G  0 lvm  
以上是创建的逻辑卷

mkdir /deta/mysqldb -pv  创建data存放的目录 
修改权限
[root@centos7 bin]#ll -d /data/mysqldb/
drwxr-xr-x 2 root root 6 Jan 23 15:47 /data/mysqldb/
[root@centos7 bin]#chown -R mysql.mysql  /data/mysqldb/
[root@centos7 bin]#ll -d /data/mysqldb/                
drwxr-xr-x 2 mysql mysql 6 Jan 23 15:47 /data/mysqldb/
[root@centos7 bin]#chmod 700  /data/mysqldb/
[root@centos7 bin]#ll -d /data/mysqldb/     
drwx------ 2 mysql mysql 6 Jan 23 15:47 /data/mysqldb/

 

第四步:执行脚本

[root@centos7 ~]#cd /usr/local/mysql/scripts/
[root@centos7 scripts]#./mysql_install_db --help 查看帮助
[root@centos7 mysql]#scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql 执行此脚本 必须是在mysql目录下

[root@centos7 support-files]#cp my-huge.cnf /etc/my.cnf
[root@centos7 support-files]#vim /etc/my.cnf
[mysqld]
port            = 3306
datadir=/data/mysqldb  这里添加数据路径                            socket          = /tmp/mysql.sock ·······


cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld //配置文件 
[root@centos7 support-files]#chkconfig --add mysqld //添加到启动脚本
[root@centos7 support-files]#chkconfig --list //查看是否添加
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

第五步: 启动

[root@centos7 support-files]#systemctl start mysqld //启动
You have new mail in /var/spool/mail/root
[root@centos7 support-files]#systemctl status mysqld
·····
   Active: active (running) since Tue 2018-01-23 16:38:23 CST; 4s 
·····
[root@centos7 support-files]#ss -ntl //查看端口3306 启动成功
LISTEN 0 80  :::3306 :::* 

服务启动会生成/tmp/mysql.sock 文件;服务停止删除此文件

 

第六步:安全初始化

数据库默认安装后
MariaDB [mysql]> select user,host from mysql.user; 
+------+-------------------+
| user | host              |
+------+-------------------+
| root | 127.0.0.1         |
| root | ::1               |
|      | centos7.qifei.com |
| root | centos7.qifei.com |
|      | localhost         |
| root | localhost         |
+------+-------------------+
6 rows in set (0.00 sec)

MariaDB [mysql]> select user,host password from mysql.user; 
+------+-------------------+
| user | password          |
+------+-------------------+
| root | 127.0.0.1         |
| root | ::1               |
|      | centos7.qifei.com |
| root | centos7.qifei.com |
|      | localhost         |
| root | localhost         |
+------+-------------------+
6 rows in set (0.00 sec)


跑脚本
[root@centos7 ~]#mysql_secure_installation (安全初始化)
请输入root口令,你没有直接回车
Enter current password for root (enter for none): 
是否设置root口令
Set root password? [Y/n] y
New password: 
Re-enter new password: 
是否删除匿名账户
Remove anonymous users? [Y/n] y
是否禁用root用户远程连接
Disallow root login remotely? [Y/n] n
是否删除test测试文件
Remove test database and access to it? [Y/n] y
是否生效保存
Reload privilege tables now? [Y/n] y

 

注意事项

[fei@centos7 ~]$mysql -uroot -p 普通用户用root登录 
Enter password: 
MariaDB [(none)]> system cat /etc/passwd //能打开所有文件 并且能修改root密码  
root:x:0:0:root:/root:/bin/bash
···········
所以 mysql的root口令千万别泄露