MySQL学习笔记-源码安装及配置

目录

1. MySQL源码安装...1

2. 安装过程中遇到的问题:...2

3. 创建MySQL服务...3

4. 创建管理脚本...6

5. 设置开机自动启动...8

 

 

1. MySQL源码安装

--cmake下载安装

http://cmake.org/download/

 

# wget http://cmake.org/files/v3.3/cmake-3.3.2.tar.gz

# tar xzvf cmake-3.3.2.tar.gz

# cd cmake-3.3.2

# ./configure

# gmake && make install

 

--创建用户

# groupadd mysql

# useradd -g mysql mysql

 

 

--设置用户操作系统资源限制

# vi /etc/security/limits.conf

mysql   soft   nproc   2047

mysql   hard   nproc   16384

mysql   soft   nofile  1024

mysql   hard   nofile  65536

 

 

--下载并解压缩MySQL源码文件

https://dev.mysql.com/downloads/mysql/

 

# tar xzvf mysql-5.6.26.tar.gz

# cd mysql-5.6.26

 

--执行cmake生成编译配置文件

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci\

-DINABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_FEDERATED_STORAGE_ENGINE=1\

-DWITH_BLACKHOLE_STORAGE_ENGINE=1\

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1\

-DWITH_PARTITION_STORAGE_ENGINE=1\

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1\

-DCOMPILATION_COMMENT='JSS formysqltest' \

-DWITH_READLINE=ON \

-DSYSCONFDIR=/data/mysqldata/3306\

-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.lock

 

--编译并安装

# make && make install

 

--修改目录权限

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

 

--修改环境变量文件

# vi /home/mysql/.bash_profile

export LANG=zh_CN.GB18030

export PATH=/usr/local/mysql/bin:$PATH

 

 

2. 安装过程中遇到的问题:

 

问题1

 

在执行cmake编译时出现了下面的错误。

用cmake . -LH 命令可重现问题

 

[root@host9 mysql-5.6.26]#cmake . -LH

-- Running cmake version 3.3.2

-- MySQL 5.6.26

-- Packaging as:mysql-5.6.26-Linux-x86_64

-- HAVE_VISIBILITY_HIDDEN

-- HAVE_VISIBILITY_HIDDEN

-- HAVE_VISIBILITY_HIDDEN

-- Could NOT find Curses(missing:  CURSES_LIBRARYCURSES_INCLUDE_PATH)

CMake Error atcmake/readline.cmake:85 (MESSAGE):

  Curses library not found.  Please install appropriate package,

 

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

Call Stack (most recent callfirst):

  cmake/readline.cmake:128 (FIND_CURSES)

  cmake/readline.cmake:202(MYSQL_USE_BUNDLED_EDITLINE)

  CMakeLists.txt:409 (MYSQL_CHECK_EDITLINE)

 

 

-- Configuring incomplete,errors occurred!

See also"/root/mysql-5.6.26/CMakeFiles/CMakeOutput.log".

See also"/root/mysql-5.6.26/CMakeFiles/CMakeError.log".

 

解决方法:安装ncurses-devel包

# yum installncurses-devel.x86_64

# make clean

# rm -rf CMakeCache.txt

# cmake . -LH

 

参考:

http://blog.chinaunix.net/uid-20682026-id-3144341.html

 

 

 

3. 创建MySQL服务

--创建数据目录

# mkdir /data

# cd /data

# mkdir -p/data/mysqldata/{3306/{data,tmp,binlog},backup,scripts}

# chown -R mysql:mysqlmysqldata

 

# su - mysql

$cd /usr/local/mysql

 

--创建参数文件

$touch /data/mysqldata/3306/my.cnf

$vi /data/mysqldata/3306/my.cnf

 

[client]

port = 3306

socket =/data/mysqldata/3306/mysql.sock

 

# The MySQL server

[mysqld]

port           = 3306

user           = mysql

socket                = /data/mysqldata/3306/mysql.sock

pid-file      = /data/mysqldata/3306/mysql.pid

basedir              = /usr/local/mysql

datadir              = /data/mysqldata/3306/data

tmpdir               = /data/mysqldata/3306/tmp

open_files_limit        = 10240

explicit_defaults_for_timestamp

sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

# Buffer

max_allowed_packet       = 256M

max_heap_table_size      = 256M

net_buffer_length   = 8K

sort_buffer_size       = 2M

join_buffer_size        = 4M

read_buffer_size      = 2M

read_rnd_buffer_size      = 16M

 

# log

log-bin = /data/mysqldata/3306/binlog/mysql-bin

binlog_cache_size   = 32M

max_binlog_cache_size  = 512M

max_binlog_size                = 512M

binlog_format           = mixed

log_output                 = FILE

log-error           = ../mysql-error.log

slow_query_log                 = 1

slow_query_log_file         = ../slow_query.log

general_log               = 0

general_log_file       = ../general_query.log

expire-logs-days       = 14

 

# InnoDB

innodb_data_file_path    = ibdatal:2048M:autoextend

innodb_log_file_size         = 256M

innodb_log_files_in_group       = 3

innodb_buffer_pool_size          = 1024M

 

[mysql]

no-auto-rehash

prompt              = (\u@\h) [\d]>\

default-character-set       =gbk

 

--初始化数据库

$/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql

Installing MySQL systemtables...2015-09-25 16:19:57 0 [Note] /usr/local/mysql/bin/mysqld (mysqld5.6.26-log) starting as process 30402 ...

OK

 

Filling helptables...2015-09-25 16:20:01 0 [Note] /usr/local/mysql/bin/mysqld (mysqld5.6.26-log) starting as process 30425 ...

OK

 

To start mysqld at boot timeyou have to copy

support-files/mysql.server tothe right place for your system

 

PLEASE REMEMBER TO SET APASSWORD FOR THE MySQL root USER !

To do so, start the server,then issue the following commands:

 

  /usr/local/mysql/bin/mysqladmin -u rootpassword 'new-password'

  /usr/local/mysql/bin/mysqladmin -u root -hhost9.localdomain password 'new-password'

 

Alternatively you can run:

 

 /usr/local/mysql/bin/mysql_secure_installation

 

which will also give you theoption of removing the test

databases and anonymous usercreated by default.  This is

strongly recommended forproduction servers.

 

See the manual for moreinstructions.

 

You can start the MySQL daemonwith:

 

  cd . ; /usr/local/mysql/bin/mysqld_safe &

 

You can test the MySQL daemonwith mysql-test-run.pl

 

  cd mysql-test ; perl mysql-test-run.pl

 

Please report any problems athttp://bugs.mysql.com/

 

The latest information aboutMySQL is available on the web at

 

  http://www.mysql.com

 

Support MySQL by buyingsupport/licenses at http://shop.mysql.com

 

WARNING: Found existing configfile /usr/local/mysql/my.cnf on the system.

Because this file might be inuse, it was not replaced,

but was used in bootstrap(unless you used --defaults-file)

and when you later start theserver.

The new default config file wascreated as /usr/local/mysql/my-new.cnf,

please compare it with yourfile and take the changes you need.

 

 

--启动数据库服务

$mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &

[1] 31069

[mysql@host9support-files]$150925 16:32:00 mysqld_safe Logging to '/data/mysqldata/3306/data/../mysql-error.log'.

150925 16:32:00 mysqld_safeStarting mysqld daemon with databases from /data/mysqldata/3306/data

 

--查看数据库进程

[mysql@host9 support-files]$netstat -lnt|grep 3306

tcp        0     0 :::3306                     :::*                        LISTEN

 

$ps -ef | grep bin/mysql | grep -v grep

mysql    31069 29398 0 16:31 pts/0    00:00:00 /bin/sh/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf

mysql    31535 31069 0 16:32 pts/0    00:00:00/usr/local/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf--basedir=/usr/local/mysql --datadir=/data/mysqldata/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/data/mysqldata/3306/data/../mysql-error.log --open-files-limit=10240- -pid-file=/data/mysqldata/3306/mysql.pid--socket=/data/mysqldata/3306/mysql.sock --port=3306

 

 

 

4. 创建管理脚本

 

--创建中间定义文件

$ vi /data/mysqldata/scripts/mysql_env.ini

 

--增加如下内容

# set env

MYSQL_USER=system

MYSQL_PASS='system'

 

# check parameter

if [ $# -ne 1 ]

then

                            HOST_PORT=3306

else

                            HOST_PORT=$1

fi

 

--修改权限

$ chmod 600 /data/mysqldata/scripts/mysql_env.ini

 

--创建启动MySQL服务脚本

$ vi /data/mysqldata/scripts/mysql_db_startup.sh

 

--增加如下内容

#!/bin/sh

 

source /data/mysqldata/scripts/mysql_env.ini

 

echo "Startup MySQLService: localhost_"${HOST_PORT}

/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/${HOST_PORT}/my.cnf &

 

--创建关闭MySQL服务脚本

$ vi /data/mysqldata/scripts/mysql_db_shutdown.sh

 

--增加如下内容

#!/bin/sh

 

source /data/mysqldata/scripts/mysql_env.ini

 

echo "Shutdown MySQLService: localhost_"${HOST_PORT}

/usr/local/mysql/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PASS} -S /data/mysqldata/${HOST_PORT}/mysql.sockshutdown

 

--创建快速登录脚本

$vi /data/mysqldata/scripts/mysqlplus.sh

 

--增加如下内容

#!/bin/sh

 

source /data/mysqldata/scripts/mysql_env.ini

 

echo "Login MySQL Service:localhost_"${HOST_PORT}

/usr/local/mysql/bin/mysql -u${MYSQL_USER} -p${MYSQL_PASS} -S /data/mysqldata/${HOST_PORT}/mysql.sock $2

 

--授予脚本权限

$ chmod u+x /data/mysqldata/scripts/*.sh

 

$ echo "export PATH=/data/mysqldata/scripts:\$PATH" >> ~/.bash_profile

$ source ~/.bash_profile

 

--测试登录MySQL

$ mysqlplus.sh

 

 

 

5. 设置开机自动启动

--修改/etc/rc.local,增加内容如下

# vi /etc/rc.local

sudo -i -u mysql/data/mysqldata/scripts/mysql_db_startup.sh 3306 >/home/mysql/mysql_db_startup.log 2>&1

 

 

 

你可能感兴趣的:(MySQL学习笔记-源码安装及配置)