CentOS install and set up MARIADB tutorial _mariadb

Source: Internet
Author: User
Tags file permissions

The article introduced the Centos use Yum installation mariadb, the relevant information can refer to this article.

Description: Must first be able to link the extranet. If you cannot access directly, you can also set up the agent, please refer to: Set up Yum agent on intranet machine

The permission requirement to use Yum is root, and if you are not, you may need to add sudo before the shell command or the SU root switch to the Super administrator. And you may need to enter a password.

1. Add Yum data source;

It is suggested that a name similar to Mariadb.repo be named:

Copy Code code as follows:

cd/etc/yum.repos.d/
Vim/etc/yum.repos.d/mariadb.repo

Then, write the contents of the file: (Recommended to use 10.0)

Copy Code code as follows:

# MARIADB 10.0 CentOS repository list-created 2015-08-12 10:59 UTC
# http://mariadb.org/mariadb/repositories/
[MARIADB]
Name = MARIADB
BaseURL = Http://yum.mariadb.org/10.0/centos6-amd64
Gpgkey=https://yum.mariadb.org/rpm-gpg-key-mariadb
Gpgcheck=1

The contents of the file are referred to the official website, and generated from the official network, set up the installation of the source warehouse specific address is:

https://downloads.mariadb.org/mariadb/repositories/

After you select the operating system version, you can view it, and other operating system installation sources can be viewed and set up here.

If the server does not support the HTTPS protocol, or if the Gpgkey is guaranteed to be OK, you can modify the gpgcheck=1 to gpgcheck=0 without checking.

2. Installing the Database

Copy Code code as follows:

# yum Remove Mariadb-server mariadb-client
Yum-y Install Mariadb-server mariadb-client

If you want to delete the old database, you can use remove, and parameter-y is a confirmation without prompting. Here, installs the server and the client, generally installs these two to be possible.

3. Start the database

If you do not need to do anything else, you can now start the database directly and test it.

Copy Code code as follows:

# view MySQL status; Close the database
# service MySQL Status
# service MySQL Stop
# Start Database
Service MySQL Start

4. Modify Root Password

# Modify Root Password
Mysqladmin-u root password ' root '

Since installed after the root password is empty, so need to set; If it is a test server, then you can use root directly, not important passwords can be set in many cases with the user name, so as not to forget and remember.

If it is an important server, use a complex password, such as a mailbox, a variety of free combinations of rules for characters, and so on.

5. Log in to the database

Mysql-u root-p

If this is the case, then you can use the above command to log in, of course, you need to enter a password. In the case of other machines, you might need the following form:

Copy Code code as follows:

Mysql-h 127.0.0.1-p 3306-u root-p

6. Simple SQL Test

>- 
View the state status of MySQL 
; 
--Shows the supported engine show 
engines; 
--Display all databases show 
databases; 
--Toggles the database context to set the default database use test for the current session 
; 
--Displays all of the tables in this database, show tables 
; 
--Create a table CREATE TABLE 
t_test ( 
 ID int (one) UNSIGNED not NULL auto_increment, 
 userId Char, 
 Lastlogintime timestamp, 
 PRIMARY KEY (ID) 
) engine=innodb DEFAULT Charset=utf8; 
 
Insert test data into 
t_test (userId) 
 values 
(' admin ') 
, (' haha ') 
; 
--Simple Query 
select * from T_test; 

7. Modify Data Storage Directory

MySQL, mariadb default data is stored in the/var/lib/mysql/directory, if you do not want to put here, or want the program and data separation, or disk reasons, need to switch to other paths, you can modify the DataDir system variables to achieve the goal.

# Stop Database

Service MySQL Stop

# Create a directory, assuming no words

Mkdir/usr/local/ieternal/mysql_data

# Copy the default database to a new location

#-a command is to copy the file attributes together, otherwise the various problems

Cp-a/var/lib/mysql/usr/local/ieternal/mysql_data

# Back up the original data

Cp-a/etc/my.cnf/etc/my.cnf_original

# Actually, check the/etc/my.cnf file to find out

# mariadb only one of the included statements in this file

# So the configuration file that needs to be modified is/ETC/MY.CNF.D/SERVER.CNF

Cp/etc/my.cnf.d/server.cnf/etc/my.cnf.d/server.cnf_original

Vim/etc/my.cnf.d/server.cnf

Then press I to enter edit mode, you can insert the relevant content. Use the keyboard up and down key can move the cursor, edit finished, press ESC to exit edit mode (enter command mode), and then enter the command: Wq Save and exit

# Add content to the Mysqld section of the file

[Mysqld] 
Datadir=/usr/local/ieternal/mysql_data/mysql 
socket=/var/lib/mysql/mysql.sock 
#default-character-set= UTF8 
character_set_server=utf8 
slow_query_log=on 
slow_query_log_file=/usr/local/ieternal/mysql_ Data/slow_query_log.log 

Among them, only datadir and socket are more important; And Default-character-set is MySQL own know, and mariadb5.5 don't know, equivalent to become character_set_server

7.1 Creating a slow query log file

Since the slow query log file was specified above, I later looked at the Err log in mariadb and found that MARIADB would not create the file on its own, so we needed to create it ourselves and modify the appropriate file permissions (such as MySQL with MySQL users, and maybe we could use a file created by the root user , this requires slow query log files to be readable and writable by MySQL users. )

Copy Code code as follows:

Touch/usr/local/ieternal/mysql_data/slow_query_log.log
chmod 666/usr/local/ieternal/mysql_data/slow_query_log.log

Then restart MySQL.

Copy Code code as follows:

Service MySQL Start

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.