Linux下安装Mariadb,我是使用的centos 7.1系统,在yum源配置好的情况下
yum search mariadb
搜索结果如下
==================================================================================== N/S matched: mariadb =====================================================================================mariadb-bench.x86_64 : MariaDB benchmark scripts and datamariadb-devel.i686 : Files for development of MariaDB/MySQL applicationsmariadb-devel.x86_64 : Files for development of MariaDB/MySQL applicationsmariadb-embedded.i686 : MariaDB as an embeddable librarymariadb-embedded.x86_64 : MariaDB as an embeddable librarymariadb-embedded-devel.i686 : Development files for MariaDB as an embeddable librarymariadb-embedded-devel.x86_64 : Development files for MariaDB as an embeddable librarymariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clientsmariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clientsmariadb-server.x86_64 : The MariaDB server and related filesmariadb.x86_64 : A community developed branch of MySQLmariadb-test.x86_64 : The test suite distributed with MariaDpercona-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文件路径