MySQL binary package installs and customizes Basedir

Source: Internet
Author: User

MySQL binary package installation and customization Basedir

Preface: MySQL Binary package, fixed dead. Basedir to be /usr/local/mysql/, But many people like to customize the directory, like I like to put /opt/app/mysql Data Catalog likes to be customized as /data/mydata/ , which had to be Basedir must make a soft link to/usr/local/mysql , I have a mild obsessive-compulsive disorder, do not want to do so, the following to see the implementation process.

1 Create a group, create a user

groupadd-g3306 MySQL

Useradd-u3306-m-s/sbin/nologin MySQL

2. unzip the binary package to create a data storage directory

mkdir-p /opt/app/

Mkdir-p/data/mydata

CP Mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz/opt/app

Cd/opt/app

Tar xvf mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz

MV Mysql-5.6.20-linux-glibc2.5-x86_64 MySQL

Chown-rmysql.mysql/opt/app/mysql/data/mydata

3. defining environment Variables

vim/etc/profile.d/mysql.sh

Export Mysql_home=/opt/app/mysql

Export path= $MYSQL _home/bin: $PATH

Su-

4. Prepare the startup scripts and add services to ensure that the startup scripts are 755 Permissions

CP-RPF Support-files/mysql.server/etc/init.d/mysql

Ll/etc/init.d/mysql

-rwxr-xr-x 1 mysql mysql 10880 07-19 00:24/etc/init.d/mysql

5. Prepare the configuration file, I like to put basedir directory , You can also put /etc/my.cnf

Vim/opt/app/mysql/my.cnf

[Client]

Socket=/opt/app/mysql/mysql.socket

[Mysqld]

Basedir =/opt/app/mysql

DataDir =/data/mydata

Port = 3306

user = MySQL

server_id = 11

Socket =/opt/app/mysql/mysql.socket

Skip-name-resolve

skip_external_locking = 1

Explicit_defaults_for_timestamp

Log-error =/opt/app/mysql/mysql-error.log

Slow_query_log = 1

Slow_query_log_file =/opt/app/mysql/mysql-slow.log

Character_set_server = GBK

innodb_file_per_table = 1

Innodb_data_home_dir =/data/mydata

Innodb_data_file_path =ibdata1:1024m:autoextend

Innodb_buffer_pool_size = 1024M

Innodb_additional_mem_pool = 32M

Innodb_log_buffer_size = 32M

Innodb_flush_log_at_trx_commit = 2

Innodb_open_files = 10000

Innodb_thread_concurrency = 32

Innodb_read_io_threads = 8

Innodb_write_io_threads =8

Innodb_log_file_size = 256M

Innodb_log_files_in_group = 3

Innodb_log_group_home_dir =/opt/app/mysql

Innodb_flush_method = O_direct

innodb_io_capacity = 2000

Innodb_undo_tablespaces = 2

Innodb_undo_logs = 128

Innodb_undo_directory =/opt/app/mysql

Max_connections = 5000

Max_connect_errors = 100000

Read_buffer_size = 2M

Sort_buffer_size = 2M

Query_cache_type = On

Query_cache_size = 64M

Tmp_table_size = 512M

Max_heap_table_size = 512M

Join_buffer_size = 2M

open_files_limit= 65535

Thread_cache_size= 128

thread_concurrency= 12

back_log= 65535

Max_allowed_packet = 64M

wait_timeout=2147483

Key_buffer_size= 512M

Bulk_insert_buffer_size = 16M

[Myisamchk]

Key_buffer_size= 64M

Read_buffer_size = 2M

Sort_buffer_size = 2M

Write_buffer_size = 2M

[Mysqld_safe]

Pid-file=/opt/app/mysql/mysqld.pid

Sql_mode=no_engine_substitution,strict_trans_tables

6. Initialize MySQL

./mysql_install_db--basedir=/opt/app/mysql--datadir=/data/mydata--DEFAULTS-FILE=/OPT/APP/MYSQL/MY.CNF

7. Check if the configuration file can be read


  mysqld--verbose--help | grep cnf
2014-09-12 11:20:21 13784 [Warning] Using unique option prefix innodb_additional_mem_pool instead of Innodb-additional-me M-pool-size is deprecated and would be removed in a future release. Please use the full name instead.
2014-09-12 11:20:21 13784 [Note] Plugin ' federated ' is disabled.
/ETC/MY.CNF/ETC/MYSQL/MY.CNF/USR/LOCAL/MYSQL/ETC/MY.CNF/

8. The most important step is to start MySQL, if not for the startup script modification, do not make a soft connection, is unable to start

[[Email protected]]#/etc/init.d/mysql Start

/etc/init.d/mysql:line 256:my_print_defaults:command not found

/etc/init.d/mysql:line 276:CD:/usr/local/mysql: no file or directory

startingmysqlcouldn ' t find MySQL server (/usr/local/mysql/[ failed ]sqld_safe)

[[Email protected]]# vim/etc/init.d/mysql

################ #截取了一段


Basedir=

Datadir=

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value Here are overriden by Value in MY.CNF.
# 0 means don ' t wait at all
# negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for Redhat/suse.
Lockdir= '/var/lock/subsys '
Lock_file_path= "$lockdir/mysql"

# The following variables is only set for letting Mysql.server find things.

# Set Some defaults
Mysqld_pid_file_path=
If Test-z "$basedir"
Then
Basedir=/usr/local/mysql
Bindir=/usr/local/mysql/bin
If Test-z "$datadir"
Then
Datadir=/usr/local/mysql/data
Fi
Sbindir=/usr/local/mysql/bin
Libexecdir=/usr/local/mysql/bin
Else
Bindir= "$basedir/bin"
If Test-z "$datadir"
Then
Datadir= "$basedir/data"
Fi
Sbindir= "$basedir/sbin"
Libexecdir= "$basedir/libexec"
Fi

#####################################

Startup script writes Dead directory

Even if you give the Basedir datadir two variables, it's still the same as starting up.


Analyze the startup script to find the problem

Sh-x/etc/init.d/mysql start

[[Email protected]-718-40065-vm scripts]# sh-x/etc/init.d/mysql start
+ basedir=
+/opt/app/mysql
/etc/init.d/mysql:line:/opt/app/mysql:is a directory
+ datadir=
+/data/mydata
/etc/init.d/mysql:line:/data/mydata:is a directory
+ service_startup_timeout=900
+ Lockdir=/var/lock/subsys
+ Lock_file_path=/var/lock/subsys/mysql
+ mysqld_pid_file_path=
+ test-z '
+ Basedir=/usr/local/mysql
+ Bindir=/usr/local/mysql/bin
+ test-z '
+ Datadir=/usr/local/mysql/data
+ Sbindir=/usr/local/mysql/bin
+ Libexecdir=/usr/local/mysql/bin
+ datadir_set=
+ lsb_functions=/lib/lsb/init-functions
+ test-f/lib/lsb/init-functions
+ . /lib/lsb/init-functions
+ Path=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/mysql/bin
+ Export PATH
+ Mode=start
+ ' [' 1-ge 1 '] '
+ Shift
+ other_args=
+ Case ' echo ' testing\c "', ' echo-n testing ' in
+ + echo ' testing\c '
+ + echo-n Testing
+ echo_n=-n
+ echo_c=
+ test-x./bin/my_print_defaults
+ Test-x/usr/local/mysql/bin/my_print_defaults
+ Test-x/usr/local/mysql/bin/mysql_print_defaults
+ conf=/etc/my.cnf
+ print_defaults=
+ Test-r/ETC/MY.CNF
+ test-z '
+ Print_defaults=my_print_defaults
+ extra_args=
+ Test-r/USR/LOCAL/MYSQL/MY.CNF
+ Test-r/USR/LOCAL/MYSQL/DATA/MY.CNF
+ + my_print_defaults mysqld server Mysql_server mysql.server
/etc/init.d/mysql:line 257:my_print_defaults:command not found
+ parse_server_arguments
+ test-z '
+ + hostname
+ Mysqld_pid_file_path=/usr/local/mysql/data/i-718-40065-vm.pid
+ Case ' $mode ' in
+ Cd/usr/local/mysql
/etc/init.d/mysql:line 277:CD:/usr/local/mysql: No file or directory
+ echo-n ' starting MySQL '
Starting mysql+ test-x/usr/local/mysql/bin/mysqld_safe
+ log_failure_msg ' couldn ' t ' find MySQL Server (/usr/local/mysql/bin/mysqld_safe) '
+/etc/redhat-lsb/lsb_log_message failure ' couldn ' t ' find MySQL Server (/usr/local/mysql/bin/mysqld_safe) '
Couldn ' t find MySQL server (/usr/local/mysql/bin/mysqld_saf[failed)



SHELL script I was the slag slag, why just gave a variable, he still can't recognize, find path

I'll give it to him if I don't recognize him. because just now I've defined MySQL variable, so I'll write it right here. $PATH


Path= "/sbin:/usr/sbin:/bin:/usr/bin: $basedir/bin"
Export PATH

Modified into

Path= "$PATH:/sbin:/usr/sbin:/bin:/usr/bin: $basedir/bin"

Export PATH

Start again.

9: Check it, start the success.

[Email protected] scripts]# NETSTAT-LNTP | grep 3306

TCP 0 0::: 3306:::* LISTEN 13699/mysqld

[Email protected] scripts]#


This article is from the "50217" blog, please be sure to keep this source http://102974.blog.51cto.com/92974/1551517

MySQL binary package installs and customizes Basedir

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.