CentOS7安装MariaDB10.1.14

时间:2023-03-09 17:30:31
CentOS7安装MariaDB10.1.14

1、下载MariaDB

下载地址:https://downloads.mariadb.org/mariadb/10.1.14/

这里选择mariadb-10.1.14-linux-x86_64.tar.gz,下载过程中如果出现404错误,可以在网站右下角选择其他镜像地址,下载完成后,使用pscp工具将其传送到CentOS中

2、解压缩

[root@localhost ~]# cd /usr/local/
[root@localhost local]# tar -zxvf mariadb-10.1.14-linux-x86_64.tar.gz
[root@localhost local]# mv mariadb-10.1.14-linux-x86_64 mysql

3、初始化数据库

[root@localhost local]# groupadd mysql

[root@localhost local]# useradd -r -g mysql -s /bin/false mysql

[root@localhost local]# cd mysql

[root@localhost mysql]# chown -R root:root .

[root@localhost mysql]# chown -R mysql:mysql data

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=./data

4、修改配置文件,并设置utf8编码格式、启动慢查询日志

[root@localhost mysql]# cp ./support-files/my-huge.cnf /etc/my.cnf

[root@localhost mysql]# vim /etc/my.cnf

[mysql]

default-character-set=utf8

...

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci

slow_query_log = 1

...

5、启动mysql服务、设置root密码

[root@localhost mysql]# ./bin/mysqld_safe --user=mysql &

[root@localhost mysql]# ./bin/mysqladmin -uroot password 'root'

6、使用mysql客户端

[root@localhost mysql]# mysql -uroot -proot

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.14-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \s
--------------
./bin/mysql  Ver 15.1 Distrib 10.1.14-MariaDB, for Linux (x86_64) using readline                                                                                         5.1

Connection id:          4
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.1.14-MariaDB MariaDB Server
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /tmp/mysql.sock
Uptime:                 37 min 55 sec

Threads: 2  Questions: 14  Slow queries: 0  Opens: 17  Flush tables: 1  Open tab                                                                                        les: 11  Queries per second avg: 0.006
--------------

MariaDB [(none)]>

7、注册系统服务
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]#  chkconfig --add mysqld # 加入开机自动启动

[root@localhost mysql]# systemctl start mysqld

8、遇到的问题

启动mysql服务时候,提示错误

/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

安装libaio-devl开发库即可

[root@localhost mysql]# yum install -y libaio-devel