弹指神通MariaDB——CentOS 7.4上安装MariaDB 10.2.21的二进制版本

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dongdong9223/article/details/86687735

转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/86687735
本文出自【我是干勾鱼的博客

Ingredients:

之前在弹指神通MariaDB——MariaDB与MySQL各版本的区别讲解过MariaDB与MySQL版本之间的区别,也在:

在阿里云的centos7上安装mysql5.6的方法

Mac下安装MySQL 5.6.40

等文章中介绍过MySQL安装的一些步骤,虽然官网在Installing MariaDB Binary Tarballs中已经将安装步骤讲解得比较详细了,但还是会发现有很多坑,今天来介绍一下MariaDB的安装。

Learn中点击A 10-minute MariaDB primer,依次点击下面几个链接,最后就能得到Installing MariaDB Binary Tarballs

1 下载

MariaDB 10.2.21 Stable可以找到MariaDB 10.2.21的下载链接,需要注意的是这里有源代码版本,有Windows版本,有Linux版本,有64位的,有32位的等等很杂乱,如果想简单的再CentOS上安装一个tar.gz的二进制版本,最好选择:

mariadb-10.2.21-linux-x86_64.tar.gz

这个版本,如图所示:

在这里插入图片描述

2 解压缩

在/opt/mariadb文件夹下解压缩文件

 tar -zxvf mariadb-10.2.21-linux-x86_64.tar.gz

在:

/usr/local/

文件夹下创建文件夹mysql:

mkdir -p /usr/local/mysql

然后将解压缩文件夹中的内容全部拷贝到这个目录下:

cp -a /opt/mariadb/mariadb-10.2.21-linux-x86_64/* /usr/local/mysql/

3 设置环境变量

修改配置文件:

vi /etc/profile

增加内容:

# set for mariadb
export MARIADB=/usr/local/mysql
export PATH=$MARIADB/bin:$PATH

4 创建用户组、用户及设置权限

4.1 创建mysql用户组

groupadd mysql

4.2 创建mysql用户

useradd -g mysql mysql

4.3 授权

给mysql文件夹授权:

cd /usr/local/
chown -R mysql:mysql /usr/local/mysql

5 复制my.cnf文件(可选)

实际操作过程中发现这个步骤应该不是必须的。

有的文章mariadb linux二进制tar包安装提出要复制配置文件并重命名为my.cnf到"/etc"目录下:

 cp support-files/my-huge.cnf /etc/my.cnf

其实support-files文件夹中有几个文件:

my-huge.cnf
my-large.cnf
my-medium.cnf
my-small.cnf

这些文件是针对不同的数据库规模的,可以查看一下文件内容中开始部分的注释了解一下。

6 复制mysql.server为mysqld

将文件:

/usr/local/mysql/support-files/mysql.server

复制为:

/etc/init.d/mysqld

命令如下:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

7 初始化

7.1 安装libaio

初始化之前要先按照libaio,命令如下:

yum install libaio

否则会报错:

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

7.2 初始化MariaDB

使用命令:

./scripts/mysql_install_db --user=mysql

或者:

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --defaults-file=/usr/local/mysql/my.cnf

进行初始化,如下:

[root@shizhi001 mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --defaults-file=/usr/local/mysql/my.cnf 
Installing MariaDB/MySQL system tables in './data' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/local/mysql/bin/mysqladmin' -u root password 'new-password'
'/usr/local/mysql/bin/mysqladmin' -u root -h shizhi001 password 'new-password'

Alternatively you can run:
'/usr/local/mysql/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr/local/mysql' ; /usr/local/mysql/bin/mysqld_safe --datadir='./data'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mysql/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

这里特别要注意! 命令是:

./scripts/mysql_install_db --user=mysql

而不是:

scripts/mysql_install_db --user=mysql

文件夹scripts前面的点号和斜杠符号不可以省略!

8 查看状态

[root@shizhi001 mysql]# service mysqld status
MariaDB is not running                                     [FAILED]

9 启动MariaDB

启动有3种方式:

  • 1:sysctmctl
  • 2:service
  • 3:./bin/mysqld_safe

推荐使用第1中sysctmctl命令启动,因为发现使用service或者mysqld_safe启动的之后,可以使用:

service mysqld status

查看出状态,但使用sysctmctl的命令:

systemctl status mysqld

查看状态却显示的是完全没有启动的状态,原因不详,不知道是否是因为CentOS7.4系统下安装二进制版本MariaDB的特点。总之使用systemctl命令启动、关闭、查看状态都是正确的。

9.1 方法1:sysctmctl

9.1.1 重新加载systemctl

第一次使用systemctl命令启动MariaDB需要重加载一下systemctl对应的库信息,后面再启动就不用了:

systemctl daemon-reload

9.1.2 启动

systemctl start mysqld

9.2 方法2:service

启动:

[root@shizhi001 mysql]# service mysqld start
Starting MariaDB.190129 15:05:00 mysqld_safe Logging to '/usr/local/mysql/data/shizhi001.err'.
190129 15:05:00 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data  [OK]

查看状态:

[root@shizhi001 mysql]# service mysqld status
MariaDB running (818)                                      [  OK  ]

9.3 方法3:./bin/mysqld_safe

[root@shizhi001 mysql]# ./bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --user=mysql &

10 进入MariaDB

初始密码为空:

[root@shizhi001 mysql]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.21-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)]> 

测试一下:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

11 参考

MariaDB.org

Installing MariaDB Binary Tarballs

弹指神通MariaDB——MariaDB与MySQL各版本的区别

Centos6.5 安装 MariaDB-10.0.20-linux-x86_64.tar.gz

Warning: Unit file of mysql.service changed on disk, ‘systemctl daemon-reload’ recommended.

mysqld:未被识别的服务(解决方法)

mariadb linux二进制tar包安装

猜你喜欢

转载自blog.csdn.net/dongdong9223/article/details/86687735