http://fanqie.blog.51cto.com/9382669/1708239
一、下载mariadb。
就是简单给大家提个醒吧,像我一样粗心的朋友可能会这样。
前几天下载mariadb的时候发现不能下载,网站可以打开但是不能下载。
这是因为默认所转到的下载站是东软,但是这个站里没有对应的下载路径。在下载页面只要换一个下载站就可以了。
如mariadb5.5的下载页面的右下角:https://downloads.mariadb.org/mariadb/5.5.46/
安装介绍:
环境:
系统:CentOS6.5_x64
软件:cmake,mariadb5.5
mariadb_10+要使用gcc5++. 可以看这里 http://cuchadanfan.blog.51cto.com/9940284/1689556
安装方式:
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
|
[root@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
|
[root@nfs cmake- 3.4 . 0 -rc2]# ./bootstrap
[root@nfs cmake- 3.4 . 0 -rc2]# make
[root@nfs cmake- 3.4 . 0 -rc2]# make install
|
三、安装mariadb。
下载地址:http://mirrors.opencas.cn/mariadb//mariadb-5.5.46/source/mariadb-5.5.46.tar.gz
1、创建用以运行mysql服务的用户。
1
2
3
4
|
[root@nfs ~]# groupadd -r -g 3306 mysql
[root@nfs ~]# useradd -r -s /sbin/nologin -g mysql -u 3306 mysql
[root@nfs ~]# id mysql uid= 3306 (mysql) gid= 3306 (mysql) groups= 3306 (mysql)
|
这里无所谓,直接创建用户也一样。
2、创建数据库目录。最好在单独的磁盘上,不要与系统在一起。我这里做实验就无所谓了。
1
2
3
|
[root@nfs ~]# mkdir -pv /mydata/data mkdir: created directory `/mydata' mkdir: created directory `/mydata/data' |
3、cmake配置选项。
不同之处:
./configure | cmake . | 检查配置选项,生成编译配置文件 |
./configure --help | cmake . -LH or ccmake . | 查看配置选项 |
make clean |
rm CMakeCache.txt | 清理此前的编译状态 |
先来看看配置选项,而且cmake也会检测当前所必须的一些工具或库。
1
2
3
4
5
6
7
8
|
[root@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
|
[root@nfs mariadb- 5.5 . 46 ]# yum install ncurses-devel -y
[root@nfs mariadb- 5.5 . 46 ]# rm CMakeCache.txt -f
[root@nfs mariadb- 5.5 . 46 ]# cmake . -LH
. Warning: Bison executable not found in PATH
|
这个bison影响不大,大家可以装上,这里就不贴了。
1
2
3
|
[root@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
[root@nfs mariadb- 5.5 . 46 ]# make
[root@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
|
[root@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
|
[root@nfs mysql]# chown -R mysql:mysql . #安装目录属主属组为mysql [root@nfs mysql]# scripts/mysql_install_db --datadir=/mydata/data --user=mysql #初始化数据库 [root@nfs mysql]# chown -R root . #安装目录属主为root [root@nfs mysql]# chown -R mysql:mysql /mydata/data #数据库目录属主组为mysql |
1
2
|
[root@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
|
[root@nfs mysql]# cp support-files/my-large.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y [root@nfs mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@nfs mysql]# chmod +x /etc/init.d/mysqld [root@nfs mysql]# chkconfig --add mysqld [root@nfs mysql]# chkconfig --list mysqld mysqld 0 :off 1 :off 2 :on 3 :on 4 :on 5 :on 6 :off
[root@nfs mysql]# vim /etc/my.cnf thread_concurrency = 4 #cpu的二倍, 在 5.6 版本中去掉了。
datadir = /mydata/data #添加这一行,数据库位置。 innodb_file_per_table = on #独立的innodb表空间文件。 |
配置文件如下
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# For advice on how to change settings please see # http: //dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL. [client] port = 3306
socket=/ var /lib/mysql/mysql.sock
default -character- set = utf8
[mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70 % of total RAM for dedicated server, else 10 %.
# innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set , remove the # and set as required.
basedir = /usr/local/mysql datadir = /mydata/data port = 3306
socket = / var /lib/mysql/mysql.sock
user = mysql innodb_file_per_table = on #Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links = 0
default -time-zone = system
default -storage-engine = InnoDB
[mysqld_safe] log-error = / var /log/mysql/mysqld.log
pid-file = / var /run/msyqld/mysqld.pid
# server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES |
番外:
配置文件中的:
[mysqld]是作用于服务端。
[mysql]只是作用于mysql组件的客户端。
[client]是作用于所有客户端组件。
尝试启动:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@nfs mysql]# service mysqld start Starting MySQL... [ OK ] [root@nfs mysql]# ss -tnlp LISTEN 0 50 *: 3306 *:* users:(( "mysqld" , 50837 , 15 ))
[root@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
[root@nfs mysql]# |
启动正常,我们先把服务停止,再做下后续操作。
1
2
|
[root@nfs mysql]# service mysqld stop Shutting down MySQL. [ OK ] |
5、后续操作。
执行程序的目录添加进path,lib目录添加到ld程序,man文档,include头文件。
1
2
3
4
5
6
7
8
|
[root@nfs mysql]# vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH [root@nfs mysql]# . /etc/profile.d/mysql.sh [root@nfs mysql]# ln -s /usr/local/mysql/ include /mysql/ /usr/ include /mysql
[root@nfs mysql]# vim /etc/man.config MANPATH /usr/local/mysql/man [root@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
|
[root@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
|
[root@nfs mysql]# cd .. [root@nfs local]# ls bin doc etc games include lib lib64 libexec mysql sbin share src
[root@nfs local]# mv mysql mysql5. 5.46
[root@nfs local]# ln -s mysql5. 5.46 mysql
[root@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
|
[root@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
|
[root@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 [root@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)]> |
查看有哪些存储引擎。