您的位置:首页 > 数据库 > MariaDB

linux下mariadb安装初始化,字符集设置

2017-02-27 15:05 387 查看
Linux下安装Mariadb,我是使用的centos 7.1系统,在yum源配置好的情况下
yum search mariadb
搜索结果如下

==================================================================================== N/S matched: mariadb =====================================================================================
mariadb-bench.x86_64 : MariaDB benchmark scripts and data
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-embedded.i686 : MariaDB as an embeddable library
mariadb-embedded.x86_64 : MariaDB as an embeddable library
mariadb-embedded-devel.i686 : Development files for MariaDB as an embeddable library
mariadb-embedded-devel.x86_64 : Development files for MariaDB as an embeddable library
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-server.x86_64 : The MariaDB server and related files
mariadb.x86_64 : A community developed branch of MySQL
mariadb-test.x86_64 : The test suite distributed with MariaD
percona-xtrabackup.x86_64 : Online backup for InnoDB/XtraDB in MySQL, Percona Server and MariaDB  Name and summary matches only, use "search all" for everything.
然后安装mariadb-server.x86_64   mariadb.x86_64这两个包(一个是服务一个是客户端,不同的系统名字可能不一样)
yum install mariadb.x86_64
yum install mariadb-server.x86_64
或者 yum groupinstall -y mariadb mariadb-server
或者直接yum install mariadb会直接装好(我第一次就是直接使用这个命令装好的)
装完后启动mariadb
systemctl start mariadb
先进一下数据库试一下,没问题就是安装完成

#########################################################################################

接下来就是初始化了
mysql_secure_installation  #这是一个快速初始化的命令
 首先他会提示输入root密码
Enter current password for root (enter for none):
初次安装时没有密码的所以直接回车
然后Change the root password? [Y/n]  修改密码
Remove anonymous users? [Y/n]   移除匿名用户,这个一般都要移除
Disallow root login remotely? [Y/n]  不允许root用户远程登录,一般是不允许,所以yes
Remove test database and access to it? [Y/n]  删除test数据库,这个不是太重要
Reload privilege tables now? [Y/n]  是否重新加载授权表  yes
这样基本初始化就完成了

###########################################################################################

设置字符集一般建议是在配置文件中设置,也可以在数据库中设置,在数据库中设置的话当服务重启后就会恢复默认字符集,会出现乱码现象
配置文件一般在/etc/my.cnf
vim /etc/my.cnf

在[mysqld]下添加如下配置
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

在[client]下添加 (有些配置文件没有[client],是因为包含了 “!includedir /etc/my.cnf.d”这句话,说明其他配置在这个目录中)
default-character-set=utf8

然后重启mariadb

登录数据库查看字符集是否设置正确 show variables like "%character%";show variables like "%collation%"

这样就设置成功了
创建数据库:CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci导入sql文件
Source sql文件路径
原文地址:http://te-amo.site/user/article/info/ARTICLE20180210043704870
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos mysql maria db linux