linux 下mariadb源码包安装

LINUX 源码包安装

1、  创建用户,并设置密码


useradd -g users -d /home/mariadb -m mariadb

passwd mariadb

2、  切换mariadb用户,下载安装包或ftp上传到目标服务器

3、  解压压缩包

tar -xzvf mariadb-10.0.14.tar.gz

4、  编译安装

cd mariadb-10.0.14

cmake . \

-DCMAKE_INSTALL_PREFIX=/home/mariadb \


-DDEFAULT_COLLATION=utf8_general_ci \









make install






-DINSTALL_SBINDIR=sbin 指向可执行文件目录(prefix/sbin)

-DMYSQL_DATADIR=/var/lib/mysql 指向mysql数据文件目录(/var/lib/mysql)

-DSYSCONFDIR=/etc/mysql 指向mysql配置文件目录(/etc/mysql)

-DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目录(prefix/lib/mysql/plugin)

-DINSTALL_MANDIR=share/man 指向man文档目录(prefix/share/man)

-DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安装目录(prefix/share)

-DINSTALL_LIBDIR=lib/mysql 指向对象代码库目录(prefix/lib/mysql)

-DINSTALL_INCLUDEDIR=include/mysql 指向头文件目录(prefix/include/mysql)

-DINSTALL_INFODIR=share/info 指向info文档存放目录(prefix/share/info)

Storage Engine相关:










-DWITH_READLINE=1 启用readline库支持(提供可编辑的命令行)

-DWITH_SSL=system 启用ssl库支持(安全套接层)

-DWITH_ZLIB=system 启用libz库支持(zib、gzib相关)

-DWTIH_LIBWRAP=0 禁用libwrap库(实现了通用TCP包装的功能,为网络服务守护进程使用)

-DMYSQL_TCP_PORT=3306 指定TCP端口为3306

-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock 指定mysql.sock路径


-DEXTRA_CHARSETS=all 启用额外的字符集类型(默认为all)

-DDEFAULT_CHARSET=utf8 指定默认的字符集为utf8

-DDEFAULT_COLLATION=utf8_general_ci 设定默认排序规则(utf8_general_ci快速/utf8_unicode_ci准确)


-DMYSQL_USER=mysql 指定mysql用户(默认为mysql)

-DWITH_DEBUG=0 禁用debug(默认为禁用)

-DENABLE_PROFILING=0 禁用Profiling分析(默认为开启)

-DWITH_COMMENT=’string’ 一个关于编译环境的描述性注释

5、  修改my.cnf


# ExampleMySQL config file for small systems.


# This isfor a system with little memory (<= 64M) where MySQL is only used

# fromtime to time and it’s important that the mysqld daemon

# doesn’tuse much resources.


# MySQL programslook for option files in a set of

#locations which depend on the deployment platform.

# You cancopy this option file to one of those

#locations. For information about these locations, see:



# In thisfile, you can use all long options that a program supports.

# If youwant to know which options a program supports, run the program

# withthe “–help” option.


# Thefollowing options will be passed to all MySQL clients


#password       =your_password

port            = 13306

socket          = /home/mariadb/mysql.sock


# Herefollows entries for some specific programs


# TheMySQL server


port            = 13306

socket          = /home/mariadb/mysql.sock

datadir =/home/mariadb/data


key_buffer_size= 16K

max_allowed_packet= 1M

table_open_cache= 4

sort_buffer_size= 64K

read_buffer_size= 256K

read_rnd_buffer_size= 256K

net_buffer_length= 2K

thread_stack= 240K

log-error= /home/mariadb/log/mysqld.log

pid-file= /home/mariadb/bin/




# Don’tlisten on a TCP/IP port at all. This can be a security enhancement,

# if allprocesses that need to connect to mysqld run on the same host.

# Allinteraction with mysqld must be made via Unix sockets or named pipes.

# Notethat using this option without enabling named pipes on Windows

# (usingthe “enable-named-pipe” option) will render mysqld useless!



server-id       = 1


#Uncomment the following if you want to log updates



# binarylogging format – mixed recommended



# Causesupdates to non-transactional engines using statement format to be

# writtendirectly to binary log. Before using this option make sure that

# thereare no dependencies between transactional and non-transactional

# tablessuch as in the statement INSERT INTO t_myisam SELECT * FROM

#t_innodb; otherwise, slaves may diverge from the master.



#Uncomment the following if you are using InnoDB tables

innodb_data_home_dir= /home/mariadb/data

innodb_data_file_path= ibdata1:10M:autoextend

innodb_log_group_home_dir= /home/mariadb/data

# You canset .._buffer_pool_size up to 50 – 80 %

# of RAMbut beware of setting memory usage too high

innodb_buffer_pool_size= 16M

innodb_additional_mem_pool_size= 2M

# Set.._log_file_size to 25 % of buffer pool size

innodb_log_file_size= 5M

innodb_log_buffer_size= 8M

innodb_flush_log_at_trx_commit= 1

innodb_lock_wait_timeout= 50




max_allowed_packet= 16M




# Removethe next comment character if you are not familiar with SQL




key_buffer_size= 8M

sort_buffer_size= 8M





6、  初始化数据库

./scripts/mysql_install_db –defaults-file=my.cnf

7、  创建文件夹

mkdir /home/mariadb/log

8、  启动数据库

./bin/mysqld_safe –defaults-file=my.cnf &

9、  为root用户创建密码

./bin/mysqladmin -u root password ‘123’ -S mysql.sock

10、  测试安装(非必须)

perl mysql-test/


邮箱地址不会被公开。 必填项已用*标注