本文参考:http://jingyan.baidu.com/article/a378c960d8a108b3282830ec.html
本文环境为:Centos7+MariaDB10.2.26
一、添加 MariaDB yum 仓库
在 RHEL/CentOS操作系统中添加 MariaDB 的 YUM 配置文件 MariaDB.repo 文件。
[root@localhost ~]#vim /etc/yum.repos.d/MariaDB.repo
Centos7,配置文件如下:
[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
==注意:行首不能有空格,否则会报错==
二、当 MariaDB 仓库地址添加好后,你可以通过下面的一行命令轻松安装 MariaDB:
[root@localhost ~]#yum install MariaDB-server MariaDB-client
三、MariaDB启停命令
# 设置成开机启动
#systemctl start mariadb
# 停止MariaDB
#systemctl stop mariadb.service
# 重启MariaDB
#systemctl restart mariadb.service
# 查看MariaDB的状态
#systemctl status mariadb
# 设置开机启动
#systemctl enable mariadb.service
启动样例:
[root@localhost ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.2.26 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Wed 2019-08-14 18:02:13 CST; 1s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 2460 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 2416 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
Process: 2414 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 2428 (mysqld)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
└─2428 /usr/sbin/mysqld
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139700325234816 [Note] InnoDB: 5.7.27 started; log sequence number 1619987
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139699823384320 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139699823384320 [Note] InnoDB: Buffer pool(s) load completed at 190814 18:02:13
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139700325234816 [Note] Plugin 'FEEDBACK' is disabled.
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139700325234816 [Note] Server socket created on IP: '::'.
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139700325234816 [Note] Reading of all Master_info entries succeeded
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139700325234816 [Note] Added new Master_info '' to hash table
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: 2019-08-14 18:02:13 139700325234816 [Note] /usr/sbin/mysqld: ready for connections.
Aug 14 18:02:13 localhost.localdomain mysqld[2428]: Version: '10.2.26-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
Aug 14 18:02:13 localhost.localdomain systemd[1]: Started MariaDB 10.2.26 database server.
[root@localhost ~]#
四、连接数据库并进入命令行
与mysql一样,在Centos命令行一输入mysql即可进行mysql的命令行,如下图:
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.2.26-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
五、字符集的设置
修改/etc/my.cnf.d/server.cnf文件,在[mysqld]下添加character-set-server=utf8
[mysqld]
# 忽略表名大小写
character-set-server=utf8