Centos7上安装MariaDB

1. 安装

1.1. 检查是否已安装 mariadb

1
yum list installed | grep mariadb

1.2. 安装MariaDB

如果未安装,执行以下命令安装命令

1
yum -y install mariadb mariadb-server

1.3. 安装完成MariaDB,首先启动MariaDB

1
systemctl start mariadb

1.4. 设置开机启动

1
systemctl enable mariadb

2. 配置

2.1. 修改配置授权远程访问

1
2
3
4
vi /etc/my.cnf

bind-address = <some ip-address>

2.2. 创建远程访问用户,并授予访问权限

1
2
3
4
5
6
7
CREATE USER 'user1'@'internet_ip' IDENTIFIED BY 'the_password';

GRANT ALL ON *.* TO 'user1'@'internet_ip';

--or reset password if user exists

SET PASSWORD FOR 'user1'@'localhost' = PASSWORD('the_password');

2.3. 设置中文字符集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
vi /etc/my.cnf.d/mariadb-server.cnf
在[mysqld]标签下添加
#character
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake

vi /etc/my.cnf.d/client.cnf
在[client]下添加
#character
default-character-set=utf8mb4

vi /etc/my.cnf.d/mysql-clients.cnf

在[mysql]中添加

#character

default-character-set=utf8mb4

2.4. 重启mariadb服务,使配置生效

1
systemctl restart mariadb

2.5. 查看版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MariaDB [(none)]> \s
--------------
mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1

Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 5.5.68-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 day 20 hours 48 min 13 sec

2.6. 查看字符集是否生效

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mysql> show variables like 'character%'; 

MariaDB [(none)]> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

log for trouble shooting
/var/log/mariadb/mariadb.log

2.7. 设置数据库对大小写不敏感

进入 /etc/my.cnf.d ,编辑server.cnf

1
2
3
vi /etc/my.cnf.d/server.cnf
在[mysqld]下添加
lower_case_table_names = 1

3. 参考文档

https://www.cnblogs.com/zhanzhan/p/7729981.html

https://blog.csdn.net/qq_35440040/article/details/86084909

作者

鹏叔

发布于

2022-11-27

更新于

2024-08-28

许可协议

评论