和MySQL类似,MariaDB是数据库服务器的管理软件,提供免费、开放源码。MySQL被Oracle收购后,主要研发团队出来单干,开发的MariaDB,并且保留了免费/开放源代码。
由于使用的是CentOS 7版本,所以这里以yum方式演示,安装MariaDB 10.1最新稳定版本。
以下均为root操作。
新增yum源,加入文件vi /etc/yum.repos.d/MariaDB.repo,具体内容也可以参考MariaDB的官方网址:
https://downloads.mariadb.org/mariadb/repositories/#mirror=syringa
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
安装MariaDB:
# yum install MariaDB-server MariaDB-client -y
#
#
启动数据库服务,设置相关启动项确保服务器开机时可以自动运行,并检测运行状态。
# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
# systemctl enable mariadb
# systemctl status mariadb
对于不支持systemctl的系统:
# /etc/init.d/mysql start
设置安全限制,这里举的例子是不设置root密码,仅本机访问,删除不必要数据:
# mysql_secure_installation
至此,全部安装完成,可以查看版本号,并建立连接:
# mysql -V
mysql Ver 15.1 Distrib 10.1.28-MariaDB, for Linux (x86_64) using readline 5.1
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.1.28-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
mysql Ver 15.1 Distrib 10.1.28-MariaDB, for Linux (x86_64) using readline 5.1
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.1.28-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
最后,建议将字符集设置为utf-8,确保未来做业务时候编码统一,且不出现乱码。修改/etc/my.cnf,增加以下几行代码:
[mysqld]
character-set-server=utf8
default-storage-engine=INNODB
character-set-server=utf8
default-storage-engine=INNODB
Leave a Reply