mariaDB 安装过程

我安装的mariaDB 10.2.21 版本,由于 10.3.12 版本的 support-files文件中和以前不一样了

第一步

 准备账号

getent passwd mysql //查看有没有mysql账号(没有的话需要创建)

useradd -r mysql -s /sbin/nologin //创建系统账号 shell类型为nologin

getent passwd 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 /data/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 文件;服务停止删除此文件

第六步:安全初始化(执行此步最好 reboot)

跑脚本
[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

 注意:

在云服务器上面搭建了MariaDb(MariaDB是MySQL源代码的一个分支),但是远程链接不上。

 首先,你要确保服务器安全组3306端口已经开放。

 在确保端口开放的情况下,如果出现错误代码1130- Host xxx is not allowed to connect to this MariaDb server,说明是权限问题。如图:

有两种解决方法:

1.授权法

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; // %:表示从任何主机连接到mysql服务器

FLUSH   PRIVILEGES;

 

2.该表法


可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入MySQL后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
mysql -u root -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root'  and host='localhost';
mysql>select host, user from user;
然后重启MySQL服务。或再执行 执行一个语句 mysql>FLUSH   PRIVILEGES;使修改生效。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值