centos7.3安装mariadb
1.开始安装, 创建MariaDB.repo文件
vim /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.1/centos7-amd64/
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
2.运行安装命令安装MariaDB
yum -y install MariaDB-server MariaDB-client
3.下载安装包,进行自动安装,安装成功之后启动MariaDB服务,并设为开机自启。
1,systemctl start mariadb #启动服务
2,systemctl enable mariadb #设置开机启动
3,systemctl restart mariadb #重新启动
4,systemctl stop mariadb.service #停止MariaDB
-
登录到数据库
mysql -uroot -p
5.进行MariaDB的相关简单配置,使用
mysql_secure_installation
命令进行配置(先退出数据库)。
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车(后面授权配置)
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
6.配置MariaDB的字符集
使用vim /etc/my.cnf.d/server.cnf命令编辑server.cnf文件,在[mysqld]标签下添加:
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
7.配置初始化完成,重启Mariadb。
systemctl restart mariadb
之后进入Mariadb,查看字符集。
show variables like "%character%";show variables like "%collation%";
8.添加用户,设置权限(用户名和密码 为 root 可自行修改)
create user root@localhost identified by 'root';
-
授予外网登陆权限
grant all privileges on *.* to username@'%' identified by 'password';
10.启动mariadb数据库
systemctl start mariadb //启动数据库