# MariaDB 10.4 CentOS repository list - created 2020-03-11 06:46 UTC# http://downloads.mariadb.org/mariadb/repositories/[mariadb]name= MariaDB
baseurl= http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
配置yum源
vim /etc/yum.repos.d/mariadb.repo
将上面的内容复制进去,保存退出。
更换国内镜像源
1
2
sudo sed -i 's#yum\.mariadb\.org#mirrors.ustc.edu.cn/mariadb/yum#' /etc/yum.repos.d/mariadb.repo
sudo sed -i 's#http://mirrors\.ustc\.edu\.cn#https://mirrors.ustc.edu.cn#g' /etc/yum.repos.d/mariadb.repo
安装MariaDB 14.x
1
yum install MariaDB-server MariaDB-client -y
如果出现了 MariaDB can’t be installed because of conflict with mariadb-libs-xxxx,则需要先卸载当前安装的版本:
1
yum remove -y mariadb-libs*
安装完成后,会提示你为root设置密码,此时需要先运行Mariadb。
MariaDB 配置开机启动
1
2
3
4
5
[root@10-13-18-4 ~]# systemctl start mariadb
[root@10-13-18-4 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
配置 MariaDB
1
mysql_secure_installation
如果出现 error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")',则说明mariadb没有启动,需要先运行Mariadb,参考上步。
1
2
3
4
5
6
7
Enter current password for root (enter for none): 输入当前的root密码(默认空),直接回车
Switch to unix_socket authentication [Y/n] 选择unix_socket登陆,y
Set root password? [Y/n] 设置新密码,y
Remove anonymous users? [Y/n] 移除匿名用户,y
Disallow root login remotely? [Y/n] 禁止root用户远程登录,y
Remove test database and access to it? [Y/n] 移除测试数据库,y
Reload privilege tables now? [Y/n] y
[root@10-13-18-4 my.cnf.d]# mysqlWelcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13Server version: 10.4.12-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 VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| 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 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+
10 rows in set(0.003 sec)MariaDB [(none)]>
开启远程访问
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@10-13-18-4 my.cnf.d]# mysqlWelcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13Server version: 10.4.12-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)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.004 sec)MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.001 sec)