Install MariaDB and MySQL

Source: Internet
Author: User

Install MariaDB and MySQL

MariaDB can be used to replace enhanced MySQL versions, but MariaDB can also be installed when MySQL is installed. (This makes sense. For example, you want to migrate data from one database/application to another database/application .)

The following describes how to install MariaDB when MySQL is installed.

Download the latest binary compilation package tar.gz (currently mariadb-5.5.24-linux-x86_64.tar.gz) and decompress it to your custom directory. This document assumes that the installation directory is/opt.

[Root @ mariadb-near-mysql ~] # Cat/etc/issue
CentOS release 6.2 (Final)

[Root @ mariadb-near-mysql ~] # Rpm-qa mysql *
Mysql-5.1.61-1.el6_2.1.x86_64
Mysql-libs-5.1.61-1.el6_2.1.x86_64
Mysql-server-5.1.61-1.el6_2.1.x86_64

[Root @ mariadb-near-mysql ~] # Ps axf | grep mysqld
2072 pts/0 S + \ _ grep mysqld
1867? S 0: 01/bin/sh/usr/bin/mysqld_safe -- datadir =/var/lib/mysql -- socket =/var/lib/mysql. sock...
1974? Sl 0: 06 \ _/usr/libexec/mysqld -- basedir =/usr -- datadir =/var/lib/mysql -- user = mysql...

Create the Directory and symbolic link of the data as follows:

[Root @ mariadb-near-mysql opt] # mkdir mariadb-data
[Root @ mariadb-near-mysql opt] # ln-s mariadb-5.5.24-linux-x86_64 mariadb
[Root @ mariadb-near-mysql opt] # ls-al
Total 20
Drwxr-xr-x. 5 root 4096.
Dr-xr-x. 23 root 4096 ..
Lrwxrwxrwx. 1 root 27 mariadb-> mariadb-5.5.24-linux-x86_64
Drwxr-xr-x. 13 root 4096 mariadb-5.5.24-linux-x86_64
Drwxr-xr-x. 2 root 4096 mariadb-data

Create mariadb and mariadb, and set the permissions of the file:

[Root @ mariadb-near-mysql opt] # groupadd -- system mariadb
[Root @ mariadb-near-mysql opt] # useradd-c "MariaDB Server"-d/opt/mariadb-g mariadb -- system mariadb
[Root @ mariadb-near-mysql opt] # chown-R mariadb: mariadb mariadb-5.5.24-linux-x86_64/
[Root @ mariadb-near-mysql opt] # chown-R mariadb: mariadb-data/

Copy my. cnf from support-files and create a new my. cnf in the/opt/mariadb directory:

[Root @ mariadb-near-mysql opt] # cp mariadb/support-files/my-medium.cnf mariadb-data/my. cnf
[Root @ mariadb-near-mysql opt] # chown mariadb: mariadb-data/my. cnf

Edit the file/opt/mariadb-data/my. cnf: add custom values, socket, port, user, and the most important settings: data DIRECTORY and base directory. the last setting is at least as follows:

[Client]
Port = 3307
Socket =/opt/mariadb-data/mariadb. sock

[Mysqld]
Datadir =/opt/mariadb-data
Basedir =/opt/mariadb
Port = 3307
Socket =/opt/mariadb-data/mariadb. sock
User = mariadb

Copy the init. d script from the support-files file to the corresponding location:

[Root @ mariadb-near-mysql opt] # cp mariadb/support-files/mysql. server/etc/init. d/mariadb
[Root @ mariadb-near-mysql opt] # chmod + x/etc/init. d/mariadb

Edit/etc/init. d/mariadb and use mariadb to replace the mysql settings as follows:

-# Provides: mysql
+ # Provides: mariadb
-Basedir =
+ Basedir =/opt/mariadb
-Datadir =
+ Datadir =/opt/mariadb-data
-Lock_file_path = "$ lockdir/mysql"
+ Lock_file_path = "$ lockdir/mariadb"

The most troublesome step is the last modification to the file. you need to tell mariadb to read the unique cnf file. add -- defaults-file =/opt/mariadb-data/my after $ bindir/mysqld_safe. cnf. the final parameter settings should be as follows:

# Give extra arguments to mysqld with the my. cnf file. This script
# May be overwritten at next upgrade.
$ Bindir/mysqld_safe -- defaults-file =/opt/mariadb-data/my. cnf -- datadir = "$ datadir" -- pid-file = "$ mysqld_pid_file_path" $ other_args>/dev/null 2> & 1 &

Explicitly specify my. cnf as the input parameter to run mysql_install_db:

[Root @ mariadb-near-mysql opt] # cd mariadb
[Root @ mariadb-near-mysql mariadb] # scripts/mysql_install_db -- defaults-file =/opt/mariadb-data/my. cnf

Now you can start MariaDB like this:

[Root @ mariadb-near-mysql opt] #/etc/init. d/mariadb start
Starting MySQL... [OK]

Set MariaDB startup to system-level startup:

[Root @ mariadb-near-mysql opt] # cd/etc/init. d
[Root @ mariadb-near-mysql init. d] # chkconfig -- add mariadb
[Root @ mariadb-near-mysql init. d] # chkconfig -- levels 3 mariadb on

Finally, the test now has two database service instances running:

[Root @ mariadb-near-mysql ~] # Mysql-e "select version ();"
+ ----------- +
| VERSION () |
+ ----------- +
| 5.1.61 |
+ ----------- +
[Root @ mariadb-near-mysql ~] # Mysql-e "select version ();" -- socket =/opt/mariadb-data/mariadb. sock
+ ---------------- +
| VERSION () |
+ ---------------- +
| 5.5.24-MariaDB |
+ ---------------- +

How to upgrade MariaDB?

To upgrade MariaDB, follow these steps:

  • Extract files from the new MariaDB package to the/opt directory (which can be placed in the same directory as the current version)
  • Stop running current MariaDB
  • Change the symbolic link mariadb to point it to the directory of the new version package.
  • Restart MariaDB
  • Run the upgrade script... but remember to provide the socket option: -- socket =/opt/mariadb-data/mariadb. sock

Install LAMP (Apache with MariaDB and PHP) in CentOS/RHEL/Scientific Linux 6)

Implementation of MariaDB Proxy read/write splitting

MariaDB details: click here
MariaDB's: click here

This article permanently updates the link address:

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.