[CentOS 7LAMP Architecture 2], MariaDB installation and configuration#

Keywords: Operation & Maintenance MariaDB MySQL Linux socket

shallow A kind of ove

Installing MariaDB

  • cd /usr/lcoal/src
  • wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  • tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  • mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
  • cd /usr/local/mariadb
  • ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
  • cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
  • vi /usr/local/mariadb/my.cnf ා define basedir and datadir
  • cp support-file/mysql.server /etc/init.d/mariadb
  • vi /etc/init.d/mariadb defines basedir, datadir, conf, and startup parameters
  • /etc/init.d/mariadb start

Download MariaDB

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
--2017-12-14 17:03:43--  https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
Resolving downloads.mariadb.com (downloads.mariadb.com)... 51.255.94.155, 2001:41d0:1004:249b::
Connecting to downloads.mariadb.com (downloads.mariadb.com)|51.255.94.155|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 541295045 (516M) [application/octet-stream]
Saving to: 'mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz'

100%[=====================================================>] 541,295,045  322KB/s   in 37m 44s

2017-12-14 17:41:29 (233 KB/s) - 'mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz' saved [541295045/541295045]
[root@localhost src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
	#mariadb unpacking and decompression process
	.
	.
	.
[root@localhost src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[root@localhost src]# cd !$
	cd /usr/local/mariadb

Compile

[root@localhost mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in '/data/mariadb' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'./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 '.' ; ./bin/mysqld_safe --datadir='/data/mariadb'

You can test the MariaDB daemon with mysql-test-run.pl
cd './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 mariadb]# echo $?
0

[root@localhost mariadb]# ls /data/mariadb/
aria_log.00000001  ib_buffer_pool  ib_logfile0  mysql               test
aria_log_control   ibdata1         ib_logfile1  performance_schema
[root@localhost mariadb]# ls support-files/
binary-configure  my-innodb-heavy-4G.cnf  my-small.cnf         mysql.server  wsrep_notify
magic             my-large.cnf            mysqld_multi.server  policy
my-huge.cnf       my-medium.cnf           mysql-log-rotate     wsrep.cnf
                  test

Select the configuration file according to the memory size and adjust the parameters appropriately

Configure MariaDB

[root@localhost mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf

Copy startup script

[root@localhost mariadb]# cp support-files/mysql.server /etc/init.d/mariadb

Edit startup script

[root@localhost mariadb]# vi /usr/local/mariadb/my.cnf
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
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

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id       = 1

# Uncomment the following if you want to log updates
#log-bin=mysql-bin

# binary logging format - mixed recommended
#binlog_format=mixed

# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but 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

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout

[root@localhost mariadb]# vi +46 /etc/init.d/mariadb
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=
datadir=

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overridden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

"/etc/init.d/mariadb" 447L, 12227C

Specify the path of 46 lines basedir and datadir basedir=/usr/local/mariadb datadir=/data/mariadb And add conf=/usr/local/mariadb/my.cnf or conf=$basedir/my.cnf After the definition is completed, you need to start the command, search / 'start' in command mode to find a behavior. bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" & Add -- defaults file = "$conf" by $bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &

If mysqld is started, it will cause conflicts.

[root@localhost mariadb]# ps aux | grep mysql
root       6662  0.0  0.0 112660   976 pts/0    S+   18:29   0:00 grep --color=auto mysql

Starting mariadb

[root@localhost mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  OK  ]
Starting mariadb (via systemctl):                          [  OK  ]

[root@localhost mariadb]# ps aux | grep mariadb
root       6711  0.0  0.0 115392  1748 ?        S    18:32   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql      6827  8.7  2.7 1583876 51500 ?       Sl   18:32   0:01 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       6874  0.0  0.0 112660   976 pts/0    S+   18:33   0:00 grep --color=auto mariadb

[root@localhost mariadb]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2470/master         
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:52133           0.0.0.0:*               LISTEN      1496/rpc.statd      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1951/rpc.mountd     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1406/sshd           
tcp        0      0 0.0.0.0:37559           0.0.0.0:*               LISTEN      -                   
tcp6       0      0 ::1:25                  :::*                    LISTEN      2470/master         
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
tcp6       0      0 :::48771                :::*                    LISTEN      -                   
tcp6       0      0 :::46184                :::*                    LISTEN      1496/rpc.statd      
tcp6       0      0 :::3306                 :::*                    LISTEN      6827/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::20048                :::*                    LISTEN      1951/rpc.mountd     
tcp6       0      0 :::22                   :::*                    LISTEN      1406/sshd 

problem

[root@localhost mariadb]# ps aux | grep mariadb
root       6711  0.0  0.0 115392  1748 ?        S    18:32   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql      6827  8.7  2.7 1583876 51500 ?       Sl   18:32   0:01 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       6874  0.0  0.0 112660   976 pts/0    S+   18:33   0:00 grep --color=auto mariadb

  • Solution 1 Go to datadir=/data/mysql and comment out datadir=/data/mysql

  • Solution 2 Add dataDir = / data / MariaDB under [mysqld] of / usr/local/mariadb/my.cnf

Then restart. If not, kill it directly.

[root@localhost mariadb]# killall mysqld]
[root@localhost mariadb]# /etc/init.d/mariadb start
Starting mariadb (via systemctl):                          [  OK  ]
[root@localhost mariadb]# ps aux | grep mariadb
root       3078  0.6  0.0 115392  1744 ?        S    05:20   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/localhost.localdomain.pid
mysql      3197  7.2  2.9 1583776 55964 ?       Sl   05:20   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/localhost.localdomain.err --pid-file=/data/mariadb/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       3236  0.0  0.0 112660   980 pts/0    S+   05:20   0:00 grep --color=auto mariadb

If ps aux | grep mariadb has no effect, restart the host

Posted by MobiTec on Fri, 01 Nov 2019 08:48:57 -0700