设为首页 收藏本站
查看: 1148|回复: 0

[经验分享] mariadb 下载与安装编译

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-11-2 10:40:46 | 显示全部楼层 |阅读模式
一、下载mariadb。
就是简单给大家提个醒吧,像我一样粗心的朋友可能会这样。
前几天下载mariadb的时候发现不能下载,网站可以打开但是不能下载。
这是因为默认所转到的下载站是东软,但是这个站里没有对应的下载路径。在下载页面只要换一个下载站就可以了。
如mariadb5.5的下载页面的右下角:https://downloads.mariadb.org/mariadb/5.5.46/
wKioL1YzVauQPee6AACtUnlRzbA957.jpg

安装介绍:

环境:
系统:CentOS6.5_x64
软件:cmake,mariadb5.5
mariadb_10+要使用gcc5++.  

安装方式:
1、Vendor: 操作系统自带的rpm包
2、MySQL官方rpm包
3、通用二进制格式
4、源码编译

我们这里选择的是源码编译安装。


二、安装cmake。
下载地址:https://cmake.org/files/v3.4/cmake-3.4.0-rc2.tar.gz
1
2
3
4
5
[iyunv@nfs cmake-3.4.0-rc2]# ls
Auxiliary                   CMakeGraphVizOptions.cmake  CompileFlags.cmake  CTestConfig.cmake     Help        Source
bootstrap                   CMakeLists.txt              configure           CTestCustom.cmake.in  Licenses    Templates
CMakeCPack.cmake            CMakeLogo.gif               CONTRIBUTING.rst    DartConfig.cmake      Modules     Tests
CMakeCPackOptions.cmake.in  cmake_uninstall.cmake.in    Copyright.txt       doxygen.config        README.rst  Utilities



可以通过configure来自定义安装,也可以执行目录下的bootstrap脚本来自动安装。
必备环境:gcc、gcc-c++
在用configure或bootstrap配置完以后会提示运行gmake,在linux上面gmake就是make,是一个符号链接。
1
2
3
[iyunv@nfs cmake-3.4.0-rc2]# ./bootstrap
[iyunv@nfs cmake-3.4.0-rc2]# make
[iyunv@nfs cmake-3.4.0-rc2]# make install




三、安装mariadb。

下载地址:http://mirrors.opencas.cn/mariad ... riadb-5.5.46.tar.gz

1、创建用以运行mysql服务的用户。
1
2
3
4
[iyunv@nfs ~]# groupadd -r -g 3306 mysql
[iyunv@nfs ~]# useradd -r -s /sbin/nologin -g mysql -u 3306 mysql
[iyunv@nfs ~]# id mysql
uid=3306(mysql) gid=3306(mysql) groups=3306(mysql)



这里无所谓,直接创建用户也一样。

2、创建数据库目录。最好在单独的磁盘上,不要与系统在一起。我这里做实验就无所谓了。
1
2
3
[iyunv@nfs ~]# mkdir -pv /mydata/data
mkdir: created directory `/mydata'
mkdir: created directory `/mydata/data'




3、cmake配置选项。
不同之处:

./configurecmake .检查配置选项,生成编译配置文件
./configure --helpcmake . -LH or ccmake .查看配置选项
make cleanrm CMakeCache.txt清理此前的编译状态

先来看看配置选项,而且cmake也会检测当前所必须的一些工具或库。
1
2
3
4
5
6
7
8
[iyunv@nfs mariadb-5.5.46]# cmake . -LH
.
.
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.



报错缺少curses库文件,而且也提示安装ncurses-devel了。报错信息在所输出的配置选项上方。
安装完ncurses-devel以后,要删除CMakeCache.txt文件。
1
2
3
4
5
[iyunv@nfs mariadb-5.5.46]# yum install ncurses-devel -y
[iyunv@nfs mariadb-5.5.46]# rm CMakeCache.txt -f
[iyunv@nfs mariadb-5.5.46]# cmake . -LH
.
Warning: Bison executable not found in PATH



这个bison影响不大,大家可以装上,这里就不贴了。
1
2
3
[iyunv@nfs mariadb-5.5.46]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DWITH_ARCHIVE_STORAGE_ENGINE=on -DWITH_BLACKHOLE_STORAGE_ENGINE=on -DWITH_READLINE=on -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_XTRADB_STORAGE_ENGINE=on  
[iyunv@nfs mariadb-5.5.46]# make
[iyunv@nfs mariadb-5.5.46]# make install



选项前面为什么加上-D,好像是表示默认属性,这点不清楚。

-DCMAKE_INSTALL_PREFIX  表示安装位置,我们一般习惯性的还是用mysql名称的目录,而且也避免有的应用使用的是这个目录。
-DMYSQL_DATADIR 表示数据存储目录
-DWITH_ARCHIVE_STORAGE_ENGINE 存储引擎archive,默认是不启用的。因为非常高的批量插入速度和实时压缩功能,和相对较差的查询功能,所以经常被用来当做仓库使用。
-DWITH_BLACKHOLE_STORAGE_ENGINE 黑洞引擎,写入的任何数据都会消失。
-DWITH_READLINE=on 附带readline行编辑库
-DWITH_SSL=system 使用系统的ssl库,要安装openssl-devel包。
-DWITH_ZLIB=system 使用系统的zlib库。

-DWITH_XTRADB_STORAGE_ENGINE 存储引擎xtradb,可以说是innodb的升级版。这个默认就是安装的。
这个配置所必须的openssl-devel要装上,zlib-devel一般默认是安装的。


cmake报错:

-- Could NOT find Boost

安装boost-devel


-- Looking for event.h - not found
安装libevent-devel。
有时候所报的软件名称不全可以用yum和grep来找到,如:“yum list all | grep event”


开始漫长的等待,编译完成并安装以后就跟下载的通用二进制包一样了。

4、初始化
在mariadb的安装目录中。

1
2
3
[iyunv@nfs mysql]# ls
bin      COPYING.LESSER  EXCEPTIONS-CLIENT  INSTALL-BINARY  man         README   share      support-files
COPYING  data            include            lib             mysql-test  scripts  sql-bench



1
2
3
4
[iyunv@nfs mysql]# chown -R mysql:mysql .            #安装目录属主属组为mysql
[iyunv@nfs mysql]# scripts/mysql_install_db --datadir=/mydata/data --user=mysql   #初始化数据库
[iyunv@nfs mysql]# chown -R root .                    #安装目录属主为root
[iyunv@nfs mysql]# chown -R mysql:mysql /mydata/data        #数据库目录属主组为mysql



1
2
[iyunv@nfs mysql]# ls /mydata/data
aria_log.00000001  aria_log_control  mysql  performance_schema  test



看来已经生成系统数据库了。
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@nfs mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[iyunv@nfs mysql]# cp support-files/mysql.server  /etc/init.d/mysqld
[iyunv@nfs mysql]# chmod +x /etc/init.d/mysqld
[iyunv@nfs mysql]# chkconfig --add mysqld
[iyunv@nfs mysql]# chkconfig --list mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

[iyunv@nfs mysql]# vim /etc/my.cnf
thread_concurrency = 4    #cpu的二倍
datadir = /mydata/data    #添加这一行,数据库位置。
innodb_file_per_table = on  #独立的innodb表空间文件。



番外:
配置文件中的:

[mysqld]是作用于服务端。
[mysql]只是作用于mysql组件的客户端。
[client]是作用于所有客户端组件。



尝试启动:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[iyunv@nfs mysql]# service mysqld start
Starting MySQL...                                          [  OK  ]
[iyunv@nfs mysql]# ss -tnlp
LISTEN     0      50     *:3306        *:*      users:(("mysqld",50837,15))

[iyunv@nfs mysql]# ll /mydata/data
total 28720
-rw-rw----. 1 mysql mysql    16384 Oct 30 11:51 aria_log.00000001
-rw-rw----. 1 mysql mysql       52 Oct 30 11:51 aria_log_control
-rw-rw----. 1 mysql mysql 18874368 Oct 30 12:08 ibdata1
-rw-rw----. 1 mysql mysql  5242880 Oct 30 12:08 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 Oct 30 12:08 ib_logfile1
drwx------. 2 mysql mysql     4096 Oct 30 11:51 mysql
-rw-rw----. 1 mysql mysql      245 Oct 30 12:08 mysql-bin.000001
-rw-rw----. 1 mysql mysql       19 Oct 30 12:08 mysql-bin.index
-rw-r-----. 1 mysql mysql     1904 Oct 30 12:08 nfs.star.com.err
-rw-rw----. 1 mysql mysql        6 Oct 30 12:08 nfs.star.com.pid
drwx------. 2 mysql mysql     4096 Oct 30 11:51 performance_schema
drwx------. 2 mysql mysql     4096 Oct 30 11:51 test
[iyunv@nfs mysql]#



启动正常,我们先把服务停止,再做下后续操作。
1
2
[iyunv@nfs mysql]# service mysqld stop
Shutting down MySQL.                                       [  OK  ]




5、后续操作。
执行程序的目录添加进path,lib目录添加到ld程序,man文档,include头文件。

1
2
3
4
5
6
7
8
[iyunv@nfs mysql]# vim /etc/profile.d/mysql.sh   
export PATH=/usr/local/mysql/bin:$PATH
[iyunv@nfs mysql]# . /etc/profile.d/mysql.sh
[iyunv@nfs mysql]# ln -s /usr/local/mysql/include/mysql/ /usr/include/mysql
[iyunv@nfs mysql]# vim /etc/man.config
MANPATH /usr/local/mysql/man
[iyunv@nfs mysql]# vim /etc/ld.so.conf.d/mysql-5.5.conf
/usr/local/mysql/lib




查看其它信息:
1
2
3
4
5
6
7
8
9
10
[iyunv@nfs mysql]# mysqld --verbose --help | less
mysqld  Ver 5.5.46-MariaDB-log for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Starts the MariaDB database server.

Usage: mysqld [OPTIONS]

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf



配置文件的读取顺序。相同配置后面的覆盖前面的。所有配置文件会合并到一起生效。
并显示出配置文件中可用的服务器变量。 定义的和没有定义的所有变量。还有启动时可用的选项。

把安装目录重命名再符号链接成安装路径的目录,这样以后升级版本,直接作符号链接就可以了。

1
2
3
4
5
6
7
8
[iyunv@nfs mysql]# cd ..
[iyunv@nfs local]# ls
bin  doc  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src
[iyunv@nfs local]# mv mysql mysql5.5.46
[iyunv@nfs local]# ln -s mysql5.5.46 mysql
[iyunv@nfs local]# ll
lrwxrwxrwx.  1 root root    11 Oct 30 12:40 mysql -> mysql5.5.46
drwxr-xr-x. 12 root mysql 4096 Oct 30 12:23 mysql5.5.46




四、数据库必要操作。

删除匿名用户, 给root创建密码
1
2
[iyunv@nfs local]# service mysqld start
Starting MySQL..                                           [  OK  ]



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@nfs local]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.46-MariaDB-log Source distribution

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

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

MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+------+--------------+----------+
| user | host         | password |
+------+--------------+----------+
| root | localhost    |          |
| root | nfs.star.com |          |
| root | 127.0.0.1    |          |
| root | ::1          |          |
|      | localhost    |          |
|      | nfs.star.com |          |
+------+--------------+----------+
6 rows in set (0.00 sec)



删除匿名用户或不用的:
1
2
3
4
5
6
7
8
MariaDB [(none)]> DROP USER ''@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> DROP USER ''@'nfs.star.com';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> DROP USER 'root'@'::1';
Query OK, 0 rows affected (0.00 sec)




root用户设置密码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
MariaDB [(none)]> UPDATE mysql.user SET password=PASSWORD('abcd1234') WHERE user='root';
Query OK, 3 rows affected (0.03 sec)
Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+------+--------------+-------------------------------------------+
| user | host         | password                                  |
+------+--------------+-------------------------------------------+
| root | localhost    | *4AD47E08DAE2BD4F0977EED5D23DC901359DF617 |
| root | nfs.star.com | *4AD47E08DAE2BD4F0977EED5D23DC901359DF617 |
| root | 127.0.0.1    | *4AD47E08DAE2BD4F0977EED5D23DC901359DF617 |
+------+--------------+-------------------------------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
MariaDB [(none)]> \q
Bye
[iyunv@nfs local]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.46-MariaDB-log Source distribution

Copyright (c) 2000, 2015, 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 ENGINES;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| Aria               | YES     | Crash-safe tables with MyISAM heritage                                     | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears)             | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                                     | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                                      | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.01 sec)

MariaDB [(none)]>



查看有哪些存储引擎。

暂时告一段落啦。谢谢大家。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-133972-1-1.html 上篇帖子: MySQL 5.7.9主从及Enhanced Multi-Threaded Slave配置 下篇帖子: mysql密码重置 下载地址 下载页面 二进制 操作系统 通用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表