服务器篇05-编译安装MariaDB

2018-01-11 12:50:30来源:oschina作者:ZHAO_JH人点击

分享
声明

操作系统:Centos7.1


数据库版本:mariadb10.2.12



官方下载地址


http://mirrors.neusoft.edu.cn/mariadb//mariadb-10.2.12/source/mariadb-10.2.12.tar.gz
环境准备

关闭防火墙


systemctl stop firewalld.service
systemctl disable firewalld.service

关闭SElinux


setenforce 0
sed -i s'/SELINUX/=enforcing/SELINUX/=disabled/' /etc/selinux/config

安装编译环境依赖关系


yum -y install gcc gcc-c++ make cmake ncurses ncurses-devel man ncurses libxml2 libxml2-devel openssl-devel bison bison-devel
安装MariaDB

下载并解压MariaDB


tar xvf mariadb-10.2.12.tar.gz
cd mariadb-10.2.12

编译安装MariaDB


cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql10 -DMYSQL_DATADIR=/mydata/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DWITHOUT_TOKUDB=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install

修改默认MySQL指向文件


mv /usr/bin/mysql /usr/bin/mysql_bak
ln -s /usr/local/mysql10/bin/mysql /usr/bin/mysql
用户

建立mysql用户[如果系统没有]


useradd mysql

设置权限


chown -R mysql.mysql /usr/local/mysql10/
配置

复制默认配置文件模版


cp -rfp /usr/local/mysql10/support-files/my-large.cnf /etc/my.cnf

/etc/mysql.cnf配置示例


[client]
#password= your_password
default-character-set = utf8
#客户端默认字符
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MariaDB server
[mysqld]
user = mysql
#默认用户
port = 3306
#mysql数据库端口
socket = /tmp/mysql.sock
#Linux系统特有,socket连接文件而不需要通过 tcp/ip 网络
skip-external-locking
#外部锁定,单数据库服务器开启,多数据库服务器需要注释掉
basedir = /usr/local/mysql10
# mysql 数据库服务安装目录
datadir = /usr/local/mysql10/data
#指定 mysql 数据库目录
log-error = /usr/local/mysql10/data/mysql_error.log
#指定mysql错误日志文件
pid-file = /usr/local/mysql10/data/mysql.pid
#指定mysql进程pid路径
key_buffer_size = 256M
#指定索引缓冲区大小
max_allowed_packet = 1M
#指定网络一次传输最大值
table_open_cache = 256
#MySQL每打开一个表,都会读入一些数据到table_open_cache缓存中,当MySQL在这个缓存中找不到相应信息时,才会去磁盘上读取
sort_buffer_size = 1M
#排序缓冲区,每个连接独占大小
read_buffer_size = 1M
#做 myisam 表全表扫描的缓冲大小
read_rnd_buffer_size = 4M
#MySQL的随机读缓冲区大小。当按任意顺序读取行时(例如,按照排序顺序),将分配一个随机读缓存区。进行排序查询时
myisam_sort_buffer_size = 64M
#MyISAM设置恢复表之时使用的缓冲区的尺寸,当在REPAIR TABLE或用CREATE INDEX创建索引或ALTER TABLE过程中排序 MyISAM索引分配的缓冲区
thread_cache_size = 8
#缓存连接线程最大数量,一般每1G内存分8,如2G设置为16
query_cache_size= 16M
#指定 mysql 查询缓冲区大小
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
#设置为 0,表示不限制并发数,这里推荐设置为0,更好去发挥CPU多核处理能力,提高并发量初始化数据库
/usr/local/mysql10/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql10 --datadir=/usr/local/mysql10/data

初始化输出信息


To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
#声明需要mysql.server服务需要把support-files/mysql.server复制到系统关键位置
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
#声明需要记住mysql数据库密码,以下两行命令为数据库初始数据库密码
'/usr/local/mysql10/bin/mysqladmin' -u root password 'new-password'
'/usr/local/mysql10/bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
'/usr/local/mysql10/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/mysql10' ; /usr/local/mysql10/bin/mysqld_safe --datadir='/usr/local/mysql10/data'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mysql10/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/配置状态检测

==【检测和所需配置不一致需要手动修改】==


检查拷贝过来的配置文件权限


[root@localhost support-files]# ll /etc/my.cnf
-rw-r--r-- 1 mysql mysql 4883 1月10 10:37 /etc/my.cnf

检查配置文件中mysql.sock的路径


[root@localhost support-files]# cat /etc/my.cnf | grep 'mysql.sock'
socket = /tmp/mysql.sock
socket = /tmp/mysql.sock

检查初始化后数据目录信息


[root@localhost data]# ll /usr/local/mysql10/data/
总用量 110660
-rw-rw---- 1 mysql mysql16384 1月10 13:59 aria_log.00000001
-rw-rw---- 1 mysql mysql52 1月10 13:59 aria_log_control
-rw-rw---- 1 mysql mysql 2789 1月10 13:59 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 1月10 13:59 ibdata1
-rw-rw---- 1 mysql mysql 50331648 1月10 13:59 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 1月10 13:59 ib_logfile1
drwx------ 2 mysql root4096 1月10 13:59 mysql
-rw-rw---- 1 mysql mysql29015 1月10 13:59 mysql-bin.000001
-rw-rw---- 1 mysql mysql19 1月10 13:59 mysql-bin.index
-rw-rw---- 1 mysql mysql 7 1月10 13:59 mysql-bin.state
drwx------ 2 mysql mysql19 1月10 13:59 performance_schema
drwxr-xr-x 2 mysql mysql19 1月10 11:02 test
[root@localhost data]#
服务启用

把服务添加到系统主要目录


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

修改启动服务脚本文件


vim /etc/init.d/mysqld

==注意路径和差异(只列出部分差异配置)==


basedir=/usr/local/mysql10
datadir=/usr/local/mysql10/data
...
bindir=/usr/local/mysql10/bin
sbindir=/usr/local/mysql10/bin
libexecdir=/usr/local/mysql10/bin
...
datadir_set=/usr/local/mysql10/data
...
conf=/etc/my.cnf
...

启动服务


/etc/init.d/mysqld start

添加致系统启动


chkconfig --add mysqld

设置开机自启


chkconfig mysqld on
服务状态检测

服务状态


[root@localhost support-files]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since 三 2018-01-10 17:12:07 CST; 1min 28s ago
Docs: man:systemd-sysv-generator(8)
Process: 30270 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
Process: 30337 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mysqld.service
├─30352 /bin/sh /usr/local/mysql10/bin/mysqld_safe --datadir=/usr/local/mysql10/data --pid-file=/usr/local/mysql10/data/mysql.pid
└─30488 /usr/local/mysql10/bin/mysqld --basedir=/usr/local/mysql10 --datadir=/usr/local/mysql10/data --plugin-dir=/usr/local/mysql10/lib/plugin --user...
1月 10 17:12:06 localhost systemd[1]: Starting LSB: start and stop MySQL...
1月 10 17:12:06 localhost mysqld[30337]: Starting MySQL.180110 17:12:06 mysqld_safe Logging to '/usr/local/mysql10/data/mysql_error.log'.
1月 10 17:12:06 localhost mysqld[30337]: 180110 17:12:06 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql10/data
1月 10 17:12:07 localhost mysqld[30337]: SUCCESS!
1月 10 17:12:07 localhost systemd[1]: Started LSB: start and stop MySQL.
[root@localhost support-files]#

进程状态


[root@localhost support-files]# ps aux | grep mysql
root 285520.00.0 107940 612 pts/1T16:04 0:00 tail -f mysql.log
root 303520.00.0 1153881732 ? S17:12 0:00 /bin/sh /usr/local/mysql10/bin/mysqld_safe --datadir=/usr/local/mysql10/data --pid-file=/usr/localmysql10/data/mysql.pid
mysql304881.22.8 1429836 101784 ?Sl 17:12 0:00 /usr/local/mysql10/bin/mysqld --basedir=/usr/local/mysql10 --datadir=/usr/local/mysql10/data --plugin-dir=/usr/local/mysql10/lib/plugin --user=mysql --log-error=/usr/local/mysql10/data/mysql_error.log --pid-file=/usr/local/mysql10/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 305260.00.0 112672 972 pts/2R+ 17:12 0:00 grep --color=auto mysql
[root@localhost support-files]#

自启状态


[root@localhost support-files]# chkconfig | grep mysqld
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@localhost support-files]# 数据库登录测试
[root@localhost support-files]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.Commands end with ; or /g.
Your MariaDB connection id is 10
Server version: 10.2.12-MariaDB-log Source distribution
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database|
+--------------------+
| information_schema |
| mysql|
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台