centos 7 系统下mariadb的安装及简单配置
mariadb的安装
1.yum list | grep mariadb <--查看系统中自带的数据库版本号
2.yum -y install mariadb* <--安装数据库及所需要的依赖环境
3.systemctl start mariadb <--启动数据库服务
4.systemctl enable mariadb <--设置开机自动启动数据库
5.mysql_secure_installation <--进行数据库的相关配置
Enter current password for root(Enter and none): <--初次直接按回车
New Password: <--设置密码
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] <--是否加载权限表 直接回车
初始化完Maraidb数据库,接下来进入登录测试
mysql -uroot -p +密码 <--登录数据库
配置Mariadb的字符集
1. 文件 /etc/my.cnf
vim /etc/my.cnf
在[mysql]标签下添加
init_connect = 'SET collection_connection = utf8_unicode_ci'
init_connect = 'SET NAMES utf8'
character-set-server = utf8
collection-server = utf8-unicode-ci
skip-character-set-client-handshake
2.文件/etc/my.cnf.d/client.cnf
vim /etc/my.cnf.d/client.cnf
在[client]标签下添加
default-character-set = utf8
配置完成,重新启动mariadb
systemctl restart mariadb
之后进入数据库,查看字符集
mysql>show variables like "%character%";show variables like "%collection%";
创建utf8编码的库:
CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;